w3resource

Yarn installation


In the previous tutorial we told you that you have to install yarn to be able to use it, this tutorial will show you different ways of installing yarn for different operating systems.

Installing yarn on Alpine, Arch and Gentoo Linux

To install yarn on Alpine Linux (3.6+) you can use the following commands:

apk add yarn

To install Yarn on Arch Linux you can use:

pacman -S yarn

To install Yarn on Gentoo Linux you can use portage:

sudo emerge --ask sys-apps/yarn

Both the RC and nightly builds of Yarn do not have packages for Alpine, Arch and Gentoo.

Installation Scripts

Yarn will be installed when you run the following commands 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

During the installation, a GPG signature will have to be verified.

If you want to use a particular version, you can also specify that using:

curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]

Manual install via tarball

It is possible to install Yarn by downloading and extracting a tarball following any of the steps below:

cd /opt
wget https://yarnpkg.com/latest.tar.gz
tar zvxf latest.tar.gz
# Now Yarn is in /opt/yarn-[version]/
cd /opt
wget https://yarnpkg.com/latest-rc.tar.gz
tar zvxf latest-rc.tar.gz
# Now Yarn is in /opt/yarn-[version]/
cd /opt
wget https://nightly.yarnpkg.com/latest.tar.gz
tar zvxf latest.tar.gz
# Now Yarn is in /opt/yarn-[version]/

Before you extract Yarn, we recommend that you verify the tarball using GPG:

wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --import
wget https://yarnpkg.com/latest.tar.gz.asc
gpg --verify latest.tar.gz.asc
# Look for a "Good signature from 'Yarn Packaging'" message in the output

Path Setup

If Yarn is not in PATH, you can follow these steps to add it and enable it to run anywhere.

It should be noted that your profile can be found in your .profile, .bash_profile, .bashrc, .zshrc, etc.

  1. You have to add this to your profile, using export PATH="$PATH:/opt/yarn-[version]/bin" (the path varies depending on where you extracted Yarn to)
  2. Log in and log out in the terminal, for the changes to take effect

If you want to access Yarn's executable globally, you need to set up the PATH environment variable in your terminal by adding export PATH="$PATH:`yarn global bin`" to your profile, or you if you are familiar with fish, you set PATH $PATH (yarn global bin) in the ~/.config/fish/config.fish file.

Installing Yarn on CentOS/ Fedora /RHEL

You can install Yarn on CentOS, Fedora and RHEL using the RPM package repository provided by Yarn.

curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo

You should configure the NodeSource repository, if you don't have Node.js is not installed.

curl --silent --location https://rpm.nodesource.com/setup_8.x | sudo bash -

Then you can run any of these commands:

sudo yum install yarn
## OR ##
sudo dnf install yarn

Installation Script

Yarn will be installed when you run the following commands 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

During the installation, a GPG signature will have to be verified.

If you want to use a particular version, you can also specify that using:

curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]

Manual install via tarball

It is possible to install Yarn by downloading and extracting a tarball following any of the steps below:

cd /opt
wget https://yarnpkg.com/latest.tar.gz
tar zvxf latest.tar.gz
# Now Yarn is in /opt/yarn-[version]/
cd /opt
wget https://yarnpkg.com/latest-rc.tar.gz
tar zvxf latest-rc.tar.gz
# Now Yarn is in /opt/yarn-[version]/
cd /opt
wget https://nightly.yarnpkg.com/latest.tar.gz
tar zvxf latest.tar.gz
# Now yarn is in /opt/yarn-[version]/

Before you extract Yarn, we recommend that you verify the tarball using GPG:

wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --import
wget https://yarnpkg.com/latest.tar.gz.asc
gpg --verify latest.tar.gz.asc
# Look for a "Good signature from 'Yarn Packaging'" message in the output

Path Setup

If Yarn is not in PATH, you can follow these steps to add it and enable it to run anywhere.

It should be noted that your profile can be found in your .profile, .bash_profile, .bashrc, .zshrc, etc.

  1. You have to add this to your profile, using export PATH="$PATH:/opt/yarn-[version]/bin" (the path varies depending on where you extracted Yarn to)
  2. Log in and log out in the terminal, for the changes to take effect

If you want to access Yarn's executable globally, you need to set up the PATH environment variable in your terminal by adding export PATH="$PATH:`yarn global bin`" to your profile, or you if you are familiar with fish, you set PATH $PATH (yarn global bin) in the ~/.config/fish/config.fish file.

Installing Yarn on Debian/Ubuntu

You can install Yarn on Debian or Ubuntu, using the Debian package repository provided by Yarn. However, you have to configure the repository first:

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

For versions of Ubuntu <=(less than or equal to 16.04) and all stable versions of Debian, you will have to configure the NodeSource repository to get the latest version of Node.js.

Once that is done, you can simply run:

sudo apt-get update && sudo apt-get install yarn

If you are using nvm, you can avoid the node installation by running:

sudo apt-get update && sudo apt-get install --no-install-recommends yarn

Path Setup

If Yarn is not in PATH, you can follow these steps to add it and enable it to run anywhere.

It should be noted that your profile can be found in your .profile, .bash_profile, .bashrc, .zshrc, etc.

1. You have to add this to your profile, using export PATH="$PATH:/opt/yarn-[version]/bin" (the path varies depending on where you extracted Yarn to)

2. Log in and log out in the terminal, for the changes to take effect

If you want to access Yarn's executable globally, you need to set up the PATH environment variable in your terminal by adding export PATH="$PATH:`yarn global bin`" to your profile, or you if you are familiar with fish, you setPATH $PATH (yarn global bin) in the ~/.config/fish/config.fish file.

Installing yarn on macOS

Homebrewm

Yarn can be installed using Homebrew package manager. This also installs Node.js if it is not installed already.

brew install yarn

if you are using nvm or anything similar, you have to ensure that your PATH lists nvm's shims before the version of Node.js installed by Homebrew.

MacPorts

Yarn can be installed using MacPorts. This also installs Node.js if it is not installed already.

sudo port install yarn

Installation Script

Yarn will be installed when you run the following commands 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

During the installation, a GPG signature will have to be verified.

If you want to use a particular version, you can also specify that using:

curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]

Manual install via tarball

It is possible to install Yarn by downloading and extracting a tarball following any of the steps below:

cd /opt
wget https://yarnpkg.com/latest.tar.gz
tar zvxf latest.tar.gz
# Now Yarn is in /opt/yarn-[version]/
cd /opt
wget https://yarnpkg.com/latest-rc.tar.gz
tar zvxf latest-rc.tar.gz
# Now Yarn is in /opt/yarn-[version]/```

```cd /opt
wget https://nightly.yarnpkg.com/latest.tar.gz
tar zvxf latest.tar.gz
# Now yarn is in /opt/yarn-[version]/

Before you extract Yarn, we recommend that you verify the tarball using GPG:

wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --import
wget https://yarnpkg.com/latest.tar.gz.asc
gpg --verify latest.tar.gz.asc
# Look for a "Good signature from 'Yarn Packaging'" message in the output

Path Setup

If Yarn is not in PATH, you can follow these steps to add it and enable it to run anywhere.

It should be noted that your profile can be found in your .profile, .bash_profile, .bashrc, .zshrc, etc.

3. You have to add this to your profile, using export PATH="$PATH:/opt/yarn-[version]/bin" (the path varies depending on where you extracted Yarn to)

4. Log in and log out in the terminal, for the changes to take effect

If you want to access Yarn's executable globally, you need to set up the PATH environment variable in your terminal by adding export PATH="$PATH:`yarn global bin`" to your profile, or you if you are familiar with fish, you set PATH $PATH (yarn global bin) in the ~/.config/fish/config.fish file.

Upgrade Yarn

Usually yarn will warn you, if there is a new version available. You can upgrade yarn using Homebrew.

brew upgrade yarn

Installing yarn on Solus

You can install yarn on solus using the Solus repository:

sudo eopkg install yarn

Both the RC and nightly builds of Yarn do not have packages for Solus

Installation Script

Yarn will be installed when you run the following commands 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

During the installation, a GPG signature will have to be verified.

If you want to use a particular version, you can also specify that using:

curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]

Manual install via tarball

It is possible to install Yarn by downloading and extracting a tarball following any of the steps below:

cd /opt
wget https://yarnpkg.com/latest.tar.gz
tar zvxf latest.tar.gz
# Now Yarn is in /opt/yarn-[version]/
cd /opt
wget https://yarnpkg.com/latest-rc.tar.gz
tar zvxf latest-rc.tar.gz
# Now Yarn is in /opt/yarn-[version]/
cd /opt
wget https://nightly.yarnpkg.com/latest.tar.gz
tar zvxf latest.tar.gz
# Now yarn is in /opt/yarn-[version]/

Before you extract Yarn, we recommend that you verify the tarball using GPG:

wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --import
wget https://yarnpkg.com/latest.tar.gz.asc
gpg --verify latest.tar.gz.asc
# Look for a "Good signature from 'Yarn Packaging'" message in the output

Path Setup

If Yarn is not in PATH, you can follow these steps to add it and enable it to run anywhere.

It should be noted that your profile can be found in your .profile, .bash_profile, .bashrc, .zshrc, etc.

  1. You have to add this to your profile, using export PATH="$PATH:/opt/yarn-[version]/bin" (the path varies depending on where you extracted Yarn to)
  2. Log in and log out in the terminal, for the changes to take effect

If you want to access Yarn's executable globally, you need to set up the PATH environment variable in your terminal by adding export PATH="$PATH:`yarn global bin`" to your profile, or you if you are familiar with fish, you set PATH $PATH (yarn global bin) in the ~/.config/fish/config.fish file.

Installing yarn for windows

There are three options available for installing Yarn on Windows.

  1. Download the installer
  2. This gives you a .msi file that will walk you through installing yarn on windows when you run it. To use the installer, you must have Node.js installed. You can download the installer using any of these links:

    • https://yarnpkg.com/latest.msi (Download installer)
    • https://yarnpkg.com/latest-rc.msi (Download installer (RC))
    • https://nightly.yarnpkg.com/latest.msi (Download installer(Nightly))
  3. Install using Chocolatey
  4. Chocolatey is a package manager for windows which you can install by following the instructions here: https://chocolatey.org/install

    once chocolatey is installed, you can then use it to install yarn.

    choco install yarn

  5. Install using Scoop
  6. You can also use scoop (a command line installer for windows) to install yarn.

    Instructions on how to set up scoop is contained here:

    scoop install yarn

    scoop will give you a suggestion to install Node.js if it is not installed:

    scoop install nodejs

Notice

You have to whitelist your project folder as well as Yarn's cache directory (%LocalAppData%\Yarn) in your antivirus software, else installation of the package will be significantly slower since every file will be scanned as it is written to the disk.

Installation Script

Yarn will be installed when you run the following commands 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

During the installation, a GPG signature will have to be verified.

If you want to use a particular version, you can also specify that using:

curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version [version]

Manual install via tarball

It is possible to install Yarn by downloading and extracting a tarball following any of the steps below:

cd /opt
wget https://yarnpkg.com/latest.tar.gz
tar zvxf latest.tar.gz
# Now Yarn is in /opt/yarn-[version]/
cd /opt
wget https://yarnpkg.com/latest-rc.tar.gz
tar zvxf latest-rc.tar.gz
# Now Yarn is in /opt/yarn-[version]/
cd /opt
wget https://nightly.yarnpkg.com/latest.tar.gz
tar zvxf latest.tar.gz
# Now yarn is in /opt/yarn-[version]/

Before you extract Yarn, we recommend that you verify the tarball using GPG:

wget -qO- https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --import
wget https://yarnpkg.com/latest.tar.gz.asc
gpg --verify latest.tar.gz.asc
# Look for a "Good signature from 'Yarn Packaging'" message in the output

Installing yarn using npm

You can use the npm package manager to install yarn. If you have node already installed, you can run:

npm install --global yarn

or

npm install --global [email protected]

The nightly builds of Yarn are not available via npm

Path Setup

You have to set up PATH environment variable in your terminal for you to access Yarn's binaries globally.

You can add set PATH=%PATH%;C:\.yarn\bin to your shell environment.

To verify that yarn is installed successfully, you have to run:

yarn - -version

Previous: Getting started with yarn
Next: Yarn Usage