centos 系统上安装 yarn


文章目录



yarn是什么

Yarn是一个用于node.js应用程序的高级包管理软件。它是任意一个其他Nodejs包管理器的快速、安全和可靠的替代方案,比npm更好的解决包依赖问题。本篇文章介绍在CentOS,Redhat和Fedora系统上安装Yarn的方法。


centos下如何安装


使用NPM安装Yarn

Yarn组件可与NPM一起安装。只需运行以下命令即可全局安装Yarn。另外,没有-g,就是仅为当前项目安装。

$ sudo npm install yarn -g

用脚本安装Yarn

这是安装Yarn最为推荐的方法。这将下载yarn档案并在home的.yarn目录下提取。脚本还设置了PATH环境变量。

$ curl -o- -L https://yarnpkg.com/install.sh | bash

使用yum安装Yarn

Yum Package Manager也提供Yarn安装包。可以使用以下命令配置yarn官方yum存储库:

$ curl -sL https://dl.yarnpkg.com/rpm/yarn.repo -o /etc/yum.repos.d/yarn.repo

现在运行下面的命令来安装它。

$ sudo yum install yarn    ## CentOS and Redhat systems 
$ sudo dnf install yarn    ## Fedora systems

可能会遇到的问题:

[root@host ~]# curl -sL https://dl.yarnpkg.com/rpm/yarn.repo -o /etc/yum.repos.d/yarn.repo
[root@host ~]# yum install yarn
已加载插件:fastestmirror
设置安装进程
Loading mirror speeds from cached hostfile
 * base: mirror.fileplanet.com
 * elrepo-kernel: repos.lax-noc.com
 * extras: repos-lax.psychz.net
 * updates: mirror.fileplanet.com
yarn                                                     | 2.9 kB     00:00 ... 
yarn/primary_db                                          |  22 kB     00:00     
解决依赖关系
--> 执行事务检查
---> Package yarn.noarch 0:1.22.4-1 will be 安装
--> 处理依赖关系 nodejs,它被软件包 yarn-1.22.4-1.noarch 需要
--> 完成依赖关系计算
错误:Package: yarn-1.22.4-1.noarch (yarn)
          Requires: nodejs
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

Yarn requires Node.js 4.0 or higher to be installed.
Yarn was installed, but doesn't seem to be working :(.

这两种提示都是没有安装node,需要先安装nodejs。

下载

wget https://nodejs.org/dist/v12.16.1/node-v12.16.1-linux-x64.tar.xz

解压遇到问题

[root@host ~]# tar -xvf node-v12.16.1-linux-x64.tar.xz 
tar (child): xz:无法 exec: 没有那个文件或目录
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

安装xz可以解决

yum install xz

解压并安装

[root@host ~]# tar -xvf node-v12.16.1-linux-x64.tar.xz 
[root@host ~]# cd node-v12.16.1-linux-x64
[root@host node-v12.16.1-linux-x64]# mkdir /usr/local/nodejs
[root@host node-v12.16.1-linux-x64]# mv * /usr/local/nodejs/

安装npm和node

ln -s /usr/local/nodejs/bin/npm /usr/local/bin/
ln -s /usr/local/nodejs/bin/node /usr/local/bin/

出自:centos 系统上安装 yarn

回到顶部