How to Install Yarn on Ubuntu 20.04?

Photo of author

By admin

As the most reliable, fast, and secure JavaScript packet manager, yarn is preferred over npm.

It automates the whole process of installing, configuring, updating, and removing npm packages.

In this blog, you will learn about ways to install Yarn on Ubuntu 20.04. But before we get into the technical side of the process, let’s learn more about Yarn and its advantages over other packet managers.

What is Yarn?

As stated in the beginning, Yarn is a packet manager for JavaScript codes which also acts as a project manager. It was released in 2016 by Facebook to overcome shortcomings of performance and security faced while using npm (Node Package Manager).

As soon as Yarn was released, it gave npm a neck-to-neck competition and made its developers make necessary improvements to fix inefficiencies.

In regards to its functionality, it allows easy sharing and use of JavaScript code residing in different parts of the world. Due to the easy accessibility, you can connect to other developers sitting far from you and use their solutions to existing problems arising during software development.

Start Installing the Yarn on Ubuntu

Note: The installation process will need Node.js on your system. Therefore, before you start with anything else, install Node.js first.

Once you have downloaded and installed Node.js, move further with the systematic guide given below. Here, you will get to learn about three different installation processes using PPA, NPM, and Script.

So, without much ado, let’s get started.

1. Method 1 – Using PPA

The method of installing Yarn on Ubuntu 20.04 using PPA

When it comes to its own repository, Yarn doesn’t have one. Instead, it uses several others, including those from its rivals, such as npm. You will learn about that as well, but before that, let’s get started with PPA installation.

You can accurately install Yarn globally on the system with the help of PPA. Hence, every user could get access to Yarn with ease.

Step 1: Import GPG key

This is the first step of this installation process. Before the installation process, first import the GPG key to verify the package.

For this, use the command;

$ curl -sL | sudo apt-key add –

Step 2: Enable repository

After the verification, enable the repository of the package manager by typing the command;

$ echo “deb stable main” | sudo tee /etc/apt/sources.list.d/yarn.list

Step 3: Install Yarn

Once the repository is enabled, move forward with Yarn installation by running the command;

$ sudo apt update && sudo apt install yarn

Step 4: Check the current version of the installed Yarn

Your installation will be complete with this step. You have to check the installed version. To do so, use the command;

$ Yarn –version

2. Method 2 – Using NPM

The method of installing Yarn on Ubuntu 20.04 using NPM

In this method of installation, you will use the npm repository to install Yarn. Start the execution with this command;

$ npm install -g yarn

Note: -g here will help you install the Yarn globally on your Linux system. You’ll have access to your systems and projects from anywhere in the world.

3. Method 3 – Using Script

The method of installing Yarn on Ubuntu 20.04 using Script

This method is one of the third options, however, it is not as viable as compared with the other two. Using Script, you will be able to install Yarn, but its access will be limited to the current user only. It will not acquire global access functionality.

To get started with the installation process, use the shell script;

$ sudo apt install curl -y

$ curl -o- -L | bash

This script will download the Yarn archive on your home directory and extract it unthe der .yarn directory.

The script will set the variable for the path environment.

These are the three popular methods for Yarn installation. You can use them according to your usability and system demands.

Once you are done, you will need knowledge of some often-used commands. Let’s do a quick go-through.

Benefits of Yarn Package Manager over npm

As you have chosen to install the Yarn package manager, you already have an idea that it is an indispensable developer tool. It works in the direction of unifying the development process and simplifying it for the greater good.

However, much remains to be understood and known. For a brief period of time, npm remained a leader among other JavaScript managers. In terms of code package management, it is designated as the gold standard. It does, however, have a few shortcomings; those shortcomings led to the development and release of Yarn by Facebook.

Here are the benefits of Yarn over npm;

  • Makes CLI output easy-to-read
  • Enables reinstallation with the help of offline mode in the absence of internet connectivity
  • Helps in retiring failed requests and improving the network resilience
  • Eliminates duplicates by resolving mismatched versions
  • Has an independent and unified structure for installation
  • Enables users to restrict licenses of already installed modules
  • Supports bower and npm workflows; allows mixing of registries

How did Yarn manage to overcome the shortcomings of npm?

Although npm and Yarn perform identical functions, yet one of them is better and the other is not. The efficiency depends upon factors like Security, Reliability, and Speed.


Yarn package manager verifies the integrity of each installed package via checksums before it is executed.


Yarn works in the direction of ensuring the baseline installation across all associated systems. It uses a lockfile format for the installation processes.


As Yarn maximizes concurrent processes and resource utilization, it ensures faster installations. It also creates a cache of every package downloaded so that they can be accessed in need without re-downloading them.

How does Yarn differ from npm with regards to common commands?

Both Yarn and npm perform the same functions and thus have a few common commands. The commands, however, differ a great deal from one another. Let’s find out how;

For installing code packages

  • npm: npm install react
  • Yarn: Yarn add react

For installing dev packages

  • npm: npm install -D
  • Yarn: Yarn add –dev webpack

For installing dependencies

  • npm: npm install
  • Yarn: Yarn

For running npm scripts

  • npm: npm run build
  • Yarn: yarn build


Yarn offers a number of advantages over npm and is highly compatible with code. It has maintained the repo and has been giving neck-to-neck competition to npm. There is no doubt that it is one of the best options for web developers, whether they are working on small or big projects. To reap the benefits of Yarn, follow this guide and install it.

Leave a Comment