Ubuntu

How to install Yarn on Ubuntu 20.04 LTS

In most of the programming projects, the management of dependencies is an important task. Using certain tools, the project libraries can control in a development project. Yarn is a fast, secure, and reliable package dependency manager for Nodejs applications. It provides multiple benefits and the best alternative over the NPM.Yarn is an open-source package manager that creates a cache for the downloaded package on your machine and you can reuse again this package when needed, without downloading this package again and again. Using checksums, yarn verifies the integrity of every installed package before executing its code. One of the other features of yarn is efficiency which you can use it in the network as well as in offline mode.

In this article, you will learn how to install yarn on Ubuntu 20.04 LTS using the command line environment.

Note: Before starting the installation of yarn, you will install Node.js on your system and you should be logged in as root user on Ubuntu 20.04 LTS.

Installation of Yarn on Ubuntu 20.04 LTS

An official repository on Ubuntu 20.04 LTS is available for the installation yarn. Using the PPA method, you can install yarn globally on the system. In this way, every system user can access this yarn.

In order to install Yarn on your system, launch the Terminal using the Ctrl + Alt + t shortcut method and then you need to perform the following steps on the terminal:

Install CURL on Ubuntu 20.04 LTS

You can install CURL from the official package repository of Ubuntu 20.04 LTS. Execute the following command to install CURL on Ubuntu 20.04 LTS:

$ sudo apt install curl

During the installation of the curl, it will notify you that extra system space will use to complete this operation. You will enter ‘y’ from your keyboard to proceed further.

Add GPG key

Once the Curl is successfully installed on your system, now, before the installation of yarn, you will add the GPG key to verify the yarn packages. To import GPG type the following command on the terminal:

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

Enable Yarn repository

To install yarn on your system, first, you will add and enable the yarn repository on Ubuntu 20.04 LTS. For this purpose, type the following command:

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

Update cache and install Yarn on Ubuntu 20.04 LTS

In this step, first, you need to update the APT cache and then you will install yarn on Ubuntu 20.04 LTS using the following command:

$ sudo apt update && sudo apt install yarn

After executing the above-mentioned command, first, it will update all system packages then it will install the new package manager yarn on your system. This command will install yarn from Ubuntu 20.04 LTS repositories.

The Node JS is dependent on Yarn. If currently, you are using Nodejs and NPM, then you will install Yarn by typing the following command on the terminal:

$ sudo apt-get install --no-install-recommends yarn

Check yarn version

Once the installation is finished on your system, after that, you will verify the installation of yarn that either it has been successfully installed on your system Ubuntu 20.04 or not. You will run the below-given command on the terminal:

$ yarn --version

After executing the above command on the terminal, you will see that the installed yarn version has displayed on your terminal window.

Congratulations! The yarn has been successfully installed on your system Ubuntu 20.04 LTS.

In this article, you have learned how you can install yarn on Ubuntu 20.04 LTS. Yarn is a good alternative to NPM that manages the dependencies of various web projects. So, if you are an experienced developer or in the learning phase then it becomes an essential part. Please give us your feedback via comments.

About the author

Karim Buzdar

Karim Buzdar

Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications. As an IT engineer and technical author, he writes for various web sites. You can reach Karim on LinkedIn.