How to Install Yarn on Ubuntu 22.04

Install Yarn on Ubuntu 22.04

In this article, we will have explained the necessary steps to install Yarn on Ubuntu 22.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

Yarn (an acronym of Yet Another Resource Negotiator) is a package manager initially introduced by Facebook, to overcome the deficiencies of a well-known package manager npm. Yarn lets users use their code and share it with other developers around the world. Also, it allows you to use other developers’ solutions to a variety of problems and makes software development easier for you.

Install Yarn on Ubuntu 22.04 LTS

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade

Step 2. Install Yarn package manager on Ubuntu Linux.

Installing Yarn on your Ubuntu 22.04 Linux system is straightforward, Now we Run the following command to import the Yarn GPG key on the Ubuntu desktop:

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

Then, enable the Yarn repository:

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

Finally, execute the following command to install Yarn installation:

sudo apt install yarn

Check yarn version:

yarnpkg --version

Step 3. How to use Yarn on Ubuntu.

Make a directory for initialization of Yarn:

mkdir yarnproject
cd yarnproject

Next, initialize the Yarn package in it:

yarn init

The command mentioned below can be used to add a dependency to your project.

yarn add [package]

Moreover, you can also add a specific version of the package as a dependency:

yarn add [package]@[version]

You can install all dependencies with the help of the command mentioned below.

yarn
yarn install

That’s all you need to do to install Yarn on Ubuntu 22.04 LTS Jammy Jellyfish. I hope you find this quick tip helpful. For further reading on the install Yarn package manager, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.