How to Install Yarn

How to Install Yarn, Yarn is a redesigned software packaging system that solves performance, security, and consistency issues with older dependency managers like npm. Here's how you can install Yarn!

Updated: 13 Mar, 23 by Susith Nonis 8 Min

List of content you will read in this article:

Many developers need to share their projects with other communities around the world. To do that, they must pack their projects into compact formats and start sharing them. Yarn is one of the most widely used and popular dependency managers developers use for making compact formats and sharing them. Yarn is popular because of its robust security, consistency, and high speed. This yarn was created as a solution to the problems and issues of its competitor, the Node package manager (npm).

As Yarn is known as a very useful manager for many developers, we explain how to install it on different operating systems using different tools.

YARN is a JavaScript dependency manager created by Google, Facebook, Exponent, and Tilde. It is commonly used on VPSs or virtual private servers, which are software platforms that host multiple applications in one place. Yarn is a framework that manages large codebases with high performance. It improves the workflow and performance of these applications.

For years, the npm client worked flawlessly at Facebook. However, as the size of their codebase and the number of engineers grew, they ran into consistency, security, and performance issues. Unable to solve each issue independently, they created a new solution designed to help manage dependencies more reliably. This updated product is called Yarn — a fast, reliable, and secure alternative to npm.

Yarn is a package manager for Node.js developed by engineers. It eliminates engineers' concerns about managing dependencies across machines or in an offline environment by using the npm registry. Furthermore, Yarn allows engineers to deploy code faster and more confidently thanks to shared code.

Before discussing how to install Yarn, let's look at its features. We mentioned four features below:

  1. High speed for application setup: Per-project caching makes Yarn faster for installing an application. Data from every package installation will be stored in Yarn's cache, making the setup process faster.
  2. Users can extend the functionality: The pre-installed plugins that come with Yarn make it useful. With these plugins, users can extend the functionality by installing more add-ons.
  3. Check the integrity of all packages: To ensure the integrity of all packages, Yarn checks them regularly before the setup process.
  4. Manage the dependencies of multiple projects: Yarn offers workspaces that provide a single repository to manage the dependencies of multiple projects.

You can set up Yarn on different operating systems like macOS, Linux, Windows, etc. In this section of this tutorial, we explain how to install Yarn on these popular operating systems. 

How to install Yarn on Linux and macOS

Before the installation process, you need to have Node.js and npm ready. To install Yarn on macOS and Linux VPS, you can use npm or cURL. First, we go with npm.

Using npm

To install Yarn using npm, follow the below instructions.

First, connect to your server using SSH. Then, open “Terminal” and type the following command to install Yarn:

sudo npm install --global yarn

After the installation process has been completed, open “Terminal” again and log in to SSH, it will enable Yarn commands.

To make sure Yarn is installed successfully, you must verify the Yarn version. To do this, run the following command in “Terminal” and then press “Enter”:

yarn –version

Using cURL

You can use the following instructions to install Yarn on Linux and macOS operating systems using cURL. 

Open “Terminal” and connect to your server via SSH. 

To install the Yarn package manager, type the below command in “Terminal”:

curl -o- -L https://yarnpkg.com/install.sh | bash

To enable Yarn, open “Terminal” again and connect to SSH. 

Run the following command and press “Enter” to verify the installation process: 

yarn –version

Using cURL to install Yarn on Debian

If you want to install Yarn on a Debian system, use the following instructions. 

Open “Terminal” on your Debian system and connect to the server via SSH. 

Now you need to add the GBG key. To do this, run the following command. This command confirms the authenticity of the downloaded packages too. 

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add –

Run the following command and press “Enter” to add the Yarn APT to the Debian package repository:

echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

After adding the repository, run the following command and press “Enter” to update the package list:

sudo apt update

Now, use the below command to install Yarn:

sudo apt install yarn

You may want to check whether the installation process was successful or not. Run the following command and press “Enter” to be sure of this:

yarn --version

Using cURL to install Yarn on CentOS

To install Yarn using cURL on CentOS, follow the steps below:

Open “Terminal” on your CentOS system and log in via SSH. 

For adding the Yarn repository, type the following command in “Terminal”:

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

Now, run the following command in “Terminal” and press “Enter” to import the repository’s GPG key:

sudo rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg

Next, you need to install Yarn by running the command below and pressing the “Enter” key:

sudo dnf install yarn

In the last step, run the below command to verify the installation:

yarn --version

How to install Yarn on Windows

In this part of the article, we plan to explain how to install the Yarn package manager on Windows systems. 

First of all, you need to download the Yarn installation package. You should download it from the official website. 

Now, double-click on the downloaded .msi file to run the installer. 

A Yarn setup window will appear. Select “Next” to continue.

Now you'll see an end-user license agreement. After reading the license, check the “accept the terms” box and click “Next” to continue. 

After that, you must choose the destination folder and select “Next” to continue. 

If you're ready to install Yarn, click “Install” when the “Yarn Setup” window appears.

The Yarn has been installed successfully. To complete the Yarn Setup Wizard, click “Finish”.

To ensure the installation process was successful, open the Command Prompt application and type the below command: 

yarn --version

Before upgrading Yarn, you have to verify the current version. To do this, run this command: 

yarn –version

Now, you can use four methods to upgrade Yarn.

Run either of the following commands to upgrade Yarn:

To update Yarn to the latest version, use this command:

yarn set version latest

For updating Yarn to a specific version, use this command:

yarn set version [version.number]

For updating Yarn on Unix machines using cURL, use this command:

curl --compressed -o- -L https://yarnpkg.com/install.sh | bash

For updating Yarn if it was installed using npm, use this command:

npm install --global yarn

Yarn is a redesigned software packaging system that solves performance, security, and consistency issues with older dependency managers like npm. It was created as an alternative to older dependency managers due to its increased functionality.

In this tutorial, we tried to provide information on how to install Yarn on various operating systems like Windows, Linux, and macOS. We also covered the basics of using Yarn, such as how to upgrade it. So, this article can be an effective way to learn about Yarn and how to install it. 

People also read: 

Susith Nonis

Susith Nonis

I'm fascinated by the IT world and how the 1's and 0's work. While I venture into the world of Technology, I try to share what I know in the simplest way with you. Not a fan of coffee, a travel addict, and a self-accredited 'master chef'.