Ubuntu

How to install Yarn on Ubuntu 22.04 LTS


Yarn is an npm-compatible JavaScript package manager that automates the installation, updating, managing, and uninstalling procedure of npm packages. This application manager assists in caching every downloaded package and parallelizing processes to speed up the installation process. Whether you are a business user working on one-shot projects or a hobbyist, Yarn got you covered!

This write-up will discuss the method to install Yarn on Ubuntu 22.04. So, let’s start!

How to Install Yarn on Ubuntu 22.04

To install Yarn on Ubuntu 22.04, you must follow the below-given step-by-step instructions.

Step 1: Update system repositories
Press “CTRL+ALT+T” to open the terminal of the Ubuntu 22.04 and run the below-given command to update system repositories:

$ sudo apt update

Step 2: Install CURL on Ubuntu 22.04
After updating the Ubuntu 22.04 system repositories, execute the following command for CURL installation:

$ sudo apt install curl

The given error-free output signifies that we have successfully installed CURL on our system:

Step 3: Import Yarn GPG key
In the next step, utilize the “curl” command for importing the Yarn GPG key to Ubuntu system repositories:

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

Step 4: Enable Yarn repository
After importing the GPG key, you have to enable the Yarn repository on your Ubuntu 22.04 system. For this purpose, write out the following command in the terminal:

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

Step 5: Install Yarn on Ubuntu 22.04
If you have carefully followed the previous steps, then at this point, your Ubuntu 22.04 system is all ready for Yarn installation. To do so, execute the below-given command:

$ sudo apt install yarn

Enter “y” to permit the installation process to continue and wait for a few minutes:

Step 6: Check Yarn version
To verify if Yarn is successfully installed or not, then check its installed version on your Ubuntu 22.04 system:

$ yarn --version

As you can see that currently Yarn version “0.32+git” is installed on our system:

How to upgrade Yarn on Ubuntu 22.04

Want to upgrade Yarn to the latest version? If yes, then first install “npm” on your system; if you do not have it already:

$ sudo apt install npm

Then, download the “Yarn” tarball and install its latest version by writing out the following command in the Ubuntu 22.04 terminal:

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

As you can see from the highlighted part of the below output, Yarn installed on our system is upgraded to the latest “1.22.18” version:

Lastly, execute the “yarn” command with the “–version” option to confirm that Yarn is upgraded to the latest version:

$ yarn --version

We have compiled the simplest method to install Yarn on Ubuntu 22.04. Moreover, the procedure to upgrade the current Yarn to the latest version is also provided to you.

Conclusion

To install Yarn on Ubuntu 22.04, first of all, install CURL with the “$ sudo apt install curl” command. After doing so, import the Yarn GPG key and enable its repository on your system. Then, execute the “$ sudo apt install yarn” for Yarn installation. You can also utilize the “$ sudo curl –compressed -o- -L https://yarnpkg.com/install.sh | bash” to upgrade Yarn. This write-up discussed the method to install Yarn on Ubuntu 22.04.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.