linux系统安装yarn,centos安装yarn

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

1、使用NPM安装Yarn

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

2、用脚本安装Yarn

这是安装Yarn最为推荐的方法。这将下载yarn档案并在home的.yarn目录下提取。脚本还设置了PATH环境变量。$ curl -o- -L https://yarnpkg.com/install.sh | bash

使用此安装Yarn仅适用于当前用户。

3、使用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 --nodigestYarn 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和nodeln -s /usr/local/nodejs/bin/npm /usr/local/bin/

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

测试npm -v[root@host bin]# npm -v

/usr/local/bin/node: /usr/local/bin/node: cannot execute binary file

这是为啥,原来是服务器配置低装的32bit系统不能运行64bit的包,或者你可能是反过来,重新下对应的包即可。可是node没有32位,只好换操作系统。

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值