How to install Yarn on Ubuntu 22.04 LTS

NPM client is a well-known package manager that maintains JavaScript dependencies. But when codebases and development expand, various issues arise related to security, consistency, and performance.

Yarn is an open-source package manager introduced by Google, Exponents, and Tilde collaboration. It overcomes the problems mentioned above as it is more secure, consistent, fast, and reliable than its competitors.

Yarn installation on Ubuntu 22.04

On Ubuntu 22.04, install Yarn using the below-provided steps.

Step 1: Update system packages

Update the system packages by opening up the terminal using “CTRL+ALT+T” and running the given command:

$ sudo apt update

Step 2: Install curl

Install curl (command-line tool) on Ubuntu 22.04:

$ sudo apt install curl

Let’s move to the next step.

Step 3: Import GPG key

Import the GPG key of Yarn that allows us to install and use this third-party tool:

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

Now move further to add a repository of Yarn.

Step 4: Add Yarn repository

After importing GPG key, add the Yarn repository into the system:

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

The repository has been added to the system, according to the output shown above.

Step 5: Install Yarn

Start Yarn installation by executing the below-supplied command:

$ sudo apt install yarn -y

Step 6: Confirm Yarn version

To confirm Yarn installation, check out its version:

$ yarn --version

Yarn version “0.32+git” on Ubuntu 22.04 is installed successfully.

How to update Yarn on Ubuntu 22.04?

To update Yarn on Ubuntu 22.04, follow the below-listed steps.

Step 1: Install NPM package

First, install “npm” on the Ubuntu 22.04 system:

$ sudo apt install npm -y

Let’s move to the next step.

Step 2: Install Latest Yarn version

Utilize the “curl” command and download the latest version of Yarn:

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

We have successfully installed Yarn “1.22.19” version on the system:

Step 3: Confirm Yarn working

After upgrading the Yarn Package manager, confirm its working:

$ yarn

Want to remove Yarn? Look at the following section.

How to remove Yarn from Ubuntu 22.04?

To remove Yarn from Ubuntu 22.04, type the given command in the terminal and execute it:

$ sudo apt remove yarn -y

We have completely demonstrated the ways to install, upgrade, and remove Yarn from Ubuntu 22.04.

Conclusion

On Ubuntu 22.04 to install Yarn, first, update the system package, and import the GPG key. In the next step, add Yarn’s repository into the system and install it using the “$ sudo apt install yarn -y” command. You can upgrade the Yarn package manager by downloading its latest setup file with the help of the “curl” command. This article discussed the methods to install, upgrade, and remove Yarn from Ubuntu 22.04.