CentOS7 安装卸载升级 Yarn

安装 Yarn

使用 yum 安装 Yarn

Yarn 官方提供的有 Yarn RPM 软件包,在添加 yum 源配置之后可使用 yum 安装:

# 添加 yum 源配置
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo

# 使用 yum 安装
sudo yum -y install yarn

查看安装的 Yarn 版本:

yarn -v

1.19.0

设置 Yarn 全局 bin 路径

查看当前 Yarn 全局 bin 路径:

yarn global bin

使用 root 用户安装的 Yarn 全局 bin 路径一般为公共路径 /usr/local/bin ,无需设置。

使用非 root 用户安装的 Yarn 全局 bin 路径一般在该用户家目录中,如 /home/<user>/.yarn/bin ,建议改为公共路径 /usr/local/bin

查看设置后的全局 bin 路径:

/usr/local/bin

Tips: 修改 Yarn 全局 bin 路径为公共路径 /usr/local/bin 之后,使用非 root 用户全局安装卸载 Node.js 软件包需要使用 sudo 命令(root 权限)。

设置 Yarn 环境变量

查看当前用户的环境变量中的 $PATH

/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

可见 Yarn 全局 bin 路径在其中,无需设置。

如果不在其中,需要手动添加路径至 Bash 配置文件 ~/.bash_profile 中:

切换 Yarn 源

手动切换 Yarn 源

常见 Node.js 软件源:

手动切换 Yarn 源,如切换至 taobao 镜像源 :

查看设置之后的 Yarn 源配置:

https://registry.npm.taobao.org/

使用 yrm 切换 Yarn 源

全局安装 yrm :

列出 yrm 支持的源:

测试各个源的连接速度:

  • npm ---- 494ms

    cnpm --- 311ms

    taobao - 110ms

    nj ----- Fetch Error

    rednpm - Fetch Error

    npmMirror 1583ms

    edunpm - Fetch Error

    yarn --- Fetch Error

切换至速度最快的的源,如 taobao:

卸载 Yarn

使用 yum 卸载

使用 yum 卸载 Node.js:

重建 yum 缓存

查看缓存的 yum repo 列表:

…...

-rw-r--r-- 1 root root 130 9月 30 09:18 yarn.repo

…...

删除含有 yarn 关键词的 repo:

清除 yum 缓存:

删除 yum 缓存文件夹:

重建 yum 缓存:

升级 Yarn

先卸载 Yarn,再安装新版即可。

参考文献

Last updated

Was this helpful?