安装
在使用 Yarn 之前,首先要在您的系统上安装 Yarn 。 以下列出了多种不同的安装方式,并且新的安装方式仍在继续添加:
Alpine
在 Alpine Linux (3.6+) 系统上通过 apk 安装 Yarn 。
apk add yarn
目前 Yarn 没有为 Alpine 提供 RC 和每日构建版本。请使用 tarball 包安装:
Installation Script
One of the easiest ways to install Yarn on macOS and generic Unix environments is via our shell script. You can install Yarn by running the following code in your terminal:
curl -o- -L https://yarnpkg.com/install.sh | bash
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --rc
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --nightly
The installation process includes verifying a GPG signature.
View the source on GitHub
You can also specify a version by running the following code in your terminal:
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]
See the releases for possible versions.
Manual Install via tarball
You can install Yarn by downloading a tarball and
extracting it anywhere.
cd /opt
wget https://yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
cd /opt
wget https://yarnpkg.com/latest-rc.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
cd /opt
wget https://nightly.yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
Before extracting Yarn, it is recommended that you verify the tarball using GPG:
wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --import
wget https://yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz.asc
gpg --verify latest.tar.gz.asc
# Look for "Good signature from 'Yarn Packaging'" in the output
Path Setup
如果未在 PATH 环境变量中找到 yarn,请按照以下步骤添加 yarn 到 PATH 环境变量中,使其可以随处运行。
注意:您的配置文件可能是 .profile
、.bash_profile
、.bashrc
、.zshrc
等。
- 将此项加入您的配置文件:
export PATH="$PATH:/opt/yarn-[version]/bin"
(路径可能根据您安装 Yarn 的位置而有差异) - 在终端中,执行登录并登出以使更改生效
为了可以全局访问 Yarn 的可执行文件,你需要在您的终端中设置 PATH
环境变量。若要执行此操作,请添加 export PATH="$PATH:`yarn global bin`"
到您的配置文件中。
Arch Linux
On Arch Linux, Yarn can be installed through the official package manager.
pacman -S yarn
Currently, there are no Arch packages available for RC or nightly builds of Yarn. Please use the tarball:
Installation Script
One of the easiest ways to install Yarn on macOS and generic Unix environments
is via our shell script. You can install Yarn by running the following code in
your terminal:
curl -o- -L https://yarnpkg.com/install.sh | bash
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --rc
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --nightly
The installation process includes verifying a GPG signature.
View the source on GitHub
You can also specify a version by running the following code in your terminal:
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]
See the releases for possible versions.
Manual Install via tarball
You can install Yarn by downloading a tarball and
extracting it anywhere.
cd /opt
wget https://yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
cd /opt
wget https://yarnpkg.com/latest-rc.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
cd /opt
wget https://nightly.yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
Before extracting Yarn, it is recommended that you verify the tarball using GPG:
wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --import
wget https://yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz.asc
gpg --verify latest.tar.gz.asc
# Look for "Good signature from 'Yarn Packaging'" in the output
Path Setup
如果未在 PATH 环境变量中找到 yarn,请按照以下步骤添加 yarn 到 PATH 环境变量中,使其可以随处运行。
注意:您的配置文件可能是 .profile
、.bash_profile
、.bashrc
、.zshrc
等。
- 将此项加入您的配置文件:
export PATH="$PATH:/opt/yarn-[version]/bin"
(路径可能根据您安装 Yarn 的位置而有差异) - 在终端中,执行登录并登出以使更改生效
为了可以全局访问 Yarn 的可执行文件,你需要在您的终端中设置 PATH
环境变量。若要执行此操作,请添加 export PATH="$PATH:`yarn global bin`"
到您的配置文件中。
CentOS / Fedora / RHEL
On CentOS, Fedora and RHEL, you can install Yarn via our RPM package repository.
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
If you do not already have Node.js installed, you should also configure
the NodeSource repository:
curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -
Then you can simply:
sudo yum install yarn
## OR ##
sudo dnf install yarn
Currently, there are no RPM packages available for RC or nightly builds of Yarn. Please use the tarball:
Installation Script
One of the easiest ways to install Yarn on macOS and generic Unix environments
is via our shell script. You can install Yarn by running the following code in
your terminal:
curl -o- -L https://yarnpkg.com/install.sh | bash
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --rc
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --nightly
The installation process includes verifying a GPG signature.
View the source on GitHub
You can also specify a version by running the following code in your terminal:
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]
See the releases for possible versions.
Manual Install via tarball
You can install Yarn by downloading a tarball and
extracting it anywhere.
cd /opt
wget https://yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
cd /opt
wget https://yarnpkg.com/latest-rc.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
cd /opt
wget https://nightly.yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
Before extracting Yarn, it is recommended that you verify the tarball using GPG:
wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --import
wget https://yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz.asc
gpg --verify latest.tar.gz.asc
# Look for "Good signature from 'Yarn Packaging'" in the output
Path Setup
如果未在 PATH 环境变量中找到 yarn,请按照以下步骤添加 yarn 到 PATH 环境变量中,使其可以随处运行。
注意:您的配置文件可能是 .profile
、.bash_profile
、.bashrc
、.zshrc
等。
- 将此项加入您的配置文件:
export PATH="$PATH:/opt/yarn-[version]/bin"
(路径可能根据您安装 Yarn 的位置而有差异) - 在终端中,执行登录并登出以使更改生效
为了可以全局访问 Yarn 的可执行文件,你需要在您的终端中设置 PATH
环境变量。若要执行此操作,请添加 export PATH="$PATH:`yarn global bin`"
到您的配置文件中。
Debian / Ubuntu
On Debian or Ubuntu Linux, you can install Yarn via our Debian package
repository. You will first need to configure the repository:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ rc main" | sudo tee /etc/apt/sources.list.d/yarn.list
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://nightly.yarnpkg.com/debian/ nightly main" | sudo tee /etc/apt/sources.list.d/yarn.list
On Ubuntu 16.04 or below and Debian Stable, you will also need to configure the NodeSource repository to get a new enough version of Node.js.
Then you can simply:
sudo apt-get update && sudo apt-get install yarn
Note: Ubuntu 17.04 comes with cmdtest
installed by default. If you’re getting errors from installing yarn
, you may want to run sudo apt remove cmdtest
first. Refer to this for more information.
If using nvm
you can avoid the node
installation by doing:
sudo apt-get update && sudo apt-get install --no-install-recommends yarn
Note: Due to the use of nodejs
instead of node
name in some distros, yarn
might complain about node
not being installed. A workaround for this is to add an alias in your .bashrc
file, like so: alias node=nodejs
. This will point yarn
to whatever version of node
you decide to use.
Path Setup
如果未在 PATH 环境变量中找到 yarn,请按照以下步骤添加 yarn 到 PATH 环境变量中,使其可以随处运行。
注意:您的配置文件可能是 .profile
、.bash_profile
、.bashrc
、.zshrc
等。
- 将此项加入您的配置文件:
export PATH="$PATH:/opt/yarn-[version]/bin"
(路径可能根据您安装 Yarn 的位置而有差异) - 在终端中,执行登录并登出以使更改生效
为了可以全局访问 Yarn 的可执行文件,你需要在您的终端中设置 PATH
环境变量。若要执行此操作,请添加 export PATH="$PATH:`yarn global bin`"
到您的配置文件中。
macOS
Homebrew
你可以通过 Homebrew 包管理工具 安装 Yarn。
如果你还未安装 Node.js,Homebrew 会自动为你安装。
brew install yarn
如果你用的是 nvm 或类似工具,你可以不用安装 Node.js ,以便使用 nvm 版本的 Node.js 并可以忽略依赖项。
brew install yarn --ignore-dependencies
MacPorts
你可以通过 MacPorts 安装 Yarn 。
如果你还未安装 Node.MacPorts 会自动为你安装。
sudo port install yarn
目前 Yarn 没有针对 Homebrew 或 MacPorts 的 RC 或每日构建版本。请使用 tarball 包安装:
Installation Script
One of the easiest ways to install Yarn on macOS and generic Unix environments
is via our shell script. You can install Yarn by running the following code in
your terminal:
curl -o- -L https://yarnpkg.com/install.sh | bash
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --rc
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --nightly
The installation process includes verifying a GPG signature.
View the source on GitHub
You can also specify a version by running the following code in your terminal:
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]
See the releases for possible versions.
Manual Install via tarball
You can install Yarn by downloading a tarball and extracting it anywhere.
cd /opt
wget https://yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
cd /opt
wget https://yarnpkg.com/latest-rc.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
cd /opt
wget https://nightly.yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
Before extracting Yarn, it is recommended that you verify the tarball using GPG:
wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --import
wget https://yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz.asc
gpg --verify latest.tar.gz.asc
# Look for "Good signature from 'Yarn Packaging'" in the output
路径设置
如果未在 PATH 环境变量中找到 yarn,请按照以下步骤添加 yarn 到 PATH 环境变量中,使其可以随处运行。
注意:您的配置文件可能是 .profile
、.bash_profile
、.bashrc
、.zshrc
等。
- 将此项加入您的配置文件:
export PATH="$PATH:/opt/yarn-[version]/bin"
(路径可能根据您安装 Yarn 的位置而有差异) - 在终端中,执行登录并登出以使更改生效
为了可以全局访问 Yarn 的可执行文件,你需要在您的终端中设置 PATH
环境变量。若要执行此操作,请添加 export PATH="$PATH:`yarn global bin`"
到您的配置文件中。
升级 Yarn
有新版时,Yarn 会给你提示。
如需升级 Yarn ,仍然可以通过 Homebrew 来升级。
brew upgrade yarn
Solus
在 Solus 系统上可以通过 Solus 仓库来安装 Yarn 。
sudo eopkg install yarn
目前 Yarn 并没有为 Solus 提供 RC 和每日构建版本。请使用 tarball 包安装:
Installation Script
One of the easiest ways to install Yarn on macOS and generic Unix environments
is via our shell script. You can install Yarn by running the following code in
your terminal:
curl -o- -L https://yarnpkg.com/install.sh | bash
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --rc
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --nightly
The installation process includes verifying a GPG signature.
View the source on GitHub
You can also specify a version by running the following code in your terminal:
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]
See the releases for possible versions.
Manual Install via tarball
You can install Yarn by downloading a tarball and extracting it anywhere.
cd /opt
wget https://yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
cd /opt
wget https://yarnpkg.com/latest-rc.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
cd /opt
wget https://nightly.yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
Before extracting Yarn, it is recommended that you verify the tarball using GPG:
wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --import
wget https://yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz.asc
gpg --verify latest.tar.gz.asc
# Look for "Good signature from 'Yarn Packaging'" in the output
Path Setup
如果未在 PATH 环境变量中找到 yarn,请按照以下步骤添加 yarn 到 PATH 环境变量中,使其可以随处运行。
注意:您的配置文件可能是 .profile
、.bash_profile
、.bashrc
、.zshrc
等。
- 将此项加入您的配置文件:
export PATH="$PATH:/opt/yarn-[version]/bin"
(路径可能根据您安装 Yarn 的位置而有差异) - 在终端中,执行登录并登出以使更改生效
为了可以全局访问 Yarn 的可执行文件,你需要在您的终端中设置 PATH
环境变量。若要执行此操作,请添加 export PATH="$PATH:`yarn global bin`"
到您的配置文件中。
Windows
在 Windows 系统中有三种安装 Yarn 的方式。
下载安装程序
你将下载到一个 .msi
文件,当它运行时会指引你将 Yarn 安装到 Windows 上。
如果你使用此安装程序,需要先安装 Node.js。
下载安装程序
下载安装程序 (RC 版本)
下载安装程序 (每日构建版)
通过 Chocolatey 安装
Chocolatey 是一个 Windows 专用的软件包管理工具。
请按照此 说明 安装 Chocolatey 。
安装 Chocolatey 之后,你就可以在控制台执行如下命令安装 Yarn 了:
choco install yarn
这也会确保你安装了 Node.js 。
通过 Scoop 安装
Scoop 是一个用于 Windows 的基于命令行的安装工具。
请按照此 说明 安装 Scoop 。
Scoop 安装后,你就可以在控制台执行如下命令安装 Yarn 了:
scoop install yarn
如果 Node.js 未被安装,scoop 会提示你安装。
例如:
scoop install nodejs
注意
请将您的项目目录和 Yarn 的缓存目录 (%LocalAppData%\Yarn) 列入杀毒软件的白名单中,否则会因为每次向磁盘写入文件时而被扫描,导致安装软件包变得很慢。
Alternatives
If you are using another OS or one of the other options specific to your OS
will not work for you, there are a couple of alternatives. You will need to
install Node.js if you don’t already have it installed.
On common Linux distributions such as Debian, Ubuntu and CentOS, it is
recommended to install Yarn via our packages instead.
Installation Script
One of the easiest ways to install Yarn on macOS and generic Unix environments
is via our shell script. You can install Yarn by running the following code in
your terminal:
curl -o- -L https://yarnpkg.com/install.sh | bash
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --rc
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --nightly
The installation process includes verifying a GPG signature.
View the source on GitHub
You can also specify a version by running the following code in your terminal:
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]
See the releases for possible versions.
Manual Install via tarball
You can install Yarn by downloading a tarball and
extracting it anywhere.
cd /opt
wget https://yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
cd /opt
wget https://yarnpkg.com/latest-rc.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
cd /opt
wget https://nightly.yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz
tar zvxf latest.tar.gz
# Yarn is now in /opt/yarn-[version]/
Before extracting Yarn, it is recommended that you verify the tarball using GPG:
wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --import
wget https://yarnpkg.comhttps://yarn.bootcss.com/latest.tar.gz.asc
gpg --verify latest.tar.gz.asc
# Look for "Good signature from 'Yarn Packaging'" in the output
Install via npm
Note: Installation of Yarn via npm is generally not recommended.
When installing Yarn with Node-based package managers, the package is not signed,
and the only integrity check performed is a basic SHA1 hash, which is a
security risk when installing system-wide apps.For these reasons, it is highly recommended that you install Yarn through the
installation method best suited to your operating system.
You can also install Yarn through the npm package manager
if you already have it installed. If you already have
Node.js installed then you should already have npm.
Once you have npm installed you can run:
npm install --global yarn
npm install --global yarn@rc
Nightly builds of Yarn are not available via npm.
Path Setup
Unix/Linux/macOS
如果未在 PATH 环境变量中找到 yarn,请按照以下步骤添加 yarn 到 PATH 环境变量中,使其可以随处运行。
注意:您的配置文件可能是 .profile
、.bash_profile
、.bashrc
、.zshrc
等。
- 将此项加入您的配置文件:
export PATH="$PATH:/opt/yarn-[version]/bin"
(路径可能根据您安装 Yarn 的位置而有差异) - 在终端中,执行登录并登出以使更改生效
为了可以全局访问 Yarn 的可执行文件,你需要在您的终端中设置 PATH
环境变量。若要执行此操作,请添加 export PATH="$PATH:`yarn global bin`"
到您的配置文件中。
Windows
你需要在控制台中设置 PATH
环境变量,以便在任何地方都可以使用 Yarn 。
通过 set PATH=%PATH%;C:\.yarn\bin
命令添加到环境变量中。
通过如下命令测试 Yarn 是否安装成功:
yarn --version