📒
notebook
  • Notebook
  • DevOps
    • Git
      • 常见 Git 操作
      • 使用 SSH 连接 Git 远程仓库
      • 使用 GPG Keys 签名 Git 提交
      • Git on macOS
    • Docker
      • macOS 安装配置 Docker
      • CentOS7 安装配置 Docker CE
  • Linux
    • CentOS
      • CentOS7 安装配置 vsftpd
      • CentOS7 设置虚拟内存
      • CentOS7 使用 acme.sh 自动申请免费 SSL 证书
      • CentOS7 修改 SSH 端口号
      • CentOS7 主机初始设置
      • 阿里云 CentOS 主机常见设置
      • CentOS7 安装配置 SS
    • nginx
      • nginx 配置 301 永久重定向
      • nginx 使用 SSL证书配置 HTTPS
      • CentOS7 安装配置 nginx
      • nginx 配置 gzip 压缩
      • nginx 代理静态网页
  • Server
    • Ghost
      • macOS 安装配置 Ghost
      • CentOS7 安装配置 Ghost
    • npm & Yarn
      • Yarn 常用命令
      • CentOS7 安装卸载升级 Yarn
      • npm & Yarn 常见错误处理
      • macOS 安装卸载升级 Yarn
    • Node.js
      • Awesome Node.js
      • CentOS7 安装卸载升级 Node.js
      • macOS 安装卸载升级 Node.js
  • Web
    • Ionic
      • 创建 Ionic & Angular 项目
      • 使用 Ionic & Cordova 构建 Android 应用
      • macOS 搭建 Ionic & Cordova 开发环境
    • CSS
      • CSS 排版技巧
      • Awesome CSS
      • CSS 三栏自适应布局
    • Angular
      • Awesome Angular
      • 创建 Angular 项目
    • HTML
      • HTML head 常用标签
      • HTML 常用 DTD 声明
      • 常用网页语义结构
    • Web 技术标准
    • JavaScript
      • Awesome JavaScript
      • JavaScript 的 eval() 函数详解
  • Mobile
    • H5
      • iOS Safari Web App 配置
  • Development Environment
    • Development Utilities
      • Awesome Windows
      • macOS 安装配置 Homebrew
      • Awesome macOS
      • macOS 安装配置 iTerm2
    • FEED
      • 常用 Gulp 插件
  • Network
    • 常见公共 DNS
  • Technology Stacks for Web Front-End Development
Powered by GitBook
On this page
  • 安装 Yarn
  • 使用 yum 安装 Yarn
  • 设置 Yarn 全局 bin 路径
  • 设置 Yarn 环境变量
  • 切换 Yarn 源
  • 手动切换 Yarn 源
  • 使用 yrm 切换 Yarn 源
  • 卸载 Yarn
  • 使用 yum 卸载
  • 重建 yum 缓存
  • 升级 Yarn
  • 参考文献

Was this helpful?

  1. Server
  2. npm & Yarn

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:

yarn config set prefix /usr/local --global

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

yarn global bin

/usr/local/bin

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

设置 Yarn 环境变量

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

echo $PATH

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

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

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

echo 'export PATH="$PATH:`yarn global bin`"' >> ~/.bash_profile
source ~/.bash_profile

切换 Yarn 源

手动切换 Yarn 源

常见 Node.js 软件源:

# npm(推荐海外使用)
https://registry.npmjs.org/

# taobao(推荐国内使用)
https://registry.npm.taobao.org/

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

yarn config set registry https://registry.npm.taobao.org/

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

yarn config get registry

使用 yrm 切换 Yarn 源

全局安装 yrm :

sudo yarn global add yrm

列出 yrm 支持的源:

yrm ls

测试各个源的连接速度:

yrm test
  • npm ---- 494ms

    cnpm --- 311ms

    taobao - 110ms

    nj ----- Fetch Error

    rednpm - Fetch Error

    npmMirror 1583ms

    edunpm - Fetch Error

    yarn --- Fetch Error

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

yrm use taobao

卸载 Yarn

使用 yum 卸载

使用 yum 卸载 Node.js:

sudo yum -y remove yarn

重建 yum 缓存

查看缓存的 yum repo 列表:

ls -l /etc/yum.repos.d/

…...

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

…...

删除含有 yarn 关键词的 repo:

sudo rm -rf /etc/yum.repos.d/yarn.repo

清除 yum 缓存:

sudo yum clean all

删除 yum 缓存文件夹:

sudo rm -rf /var/cache/yum

重建 yum 缓存:

yum makecache

升级 Yarn

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

参考文献

PreviousYarn 常用命令Nextnpm & Yarn 常见错误处理

Last updated 4 years ago

Was this helpful?

npm ----

cnpm ---

taobao -

nj -----

rednpm -

npmMirror

edunpm -

yarn ---

https://registry.npm.taobao.org/
https://registry.npmjs.org/
http://r.cnpmjs.org/
https://registry.npm.taobao.org/
https://registry.nodejitsu.com/
http://registry.mirror.cqupt.edu.cn/
https://skimdb.npmjs.com/registry/
http://registry.enpmjs.org/
https://registry.yarnpkg.com
Installation