How to Install Yarn on Ubuntu 18.04

Download Complete Linux Commands Cheat Sheet

For developers, the use of dependency managers is very common. With this, they avoid having to install dependencies of their projects manually and thus lose time. That’s why in this tutorial, we’ll show you how to install Yarn on Ubuntu to improve your VPS development workflow!

Yarn is a dependency manager for javascript that competes with NPM of Node.js

What is Yarn?

Yarn is a Javascript dependency manager created by Facebook, Google, Exponent, and Tilde. The main features that make Yarn very popular are the speed with which it processes dependencies, its security, and flexibility.

Yarn’s speed is thanks to the efficient use of the cache that removed the need to download libraries repeatedly. Meanwhile, checksum verifies the integrity of the libraries to ensure Yarn is very secure, leading to reliability.

Now, we will show how to install Yarn on Ubuntu 18.04.

How to Install Yarn on Ubuntu 18.04

The most efficient way to install Yarn on Ubuntu 18.04 is through its repository. We will be able to update the application along with the rest of the system easily:

1. Access Your Server Through SSH

To do this, we must access our server running Ubuntu 18.04. If you’re having trouble, check out our PuTTY tutorial.

2. Add the GPG Key

Run the following command:

curl -sS | sudo apt-key add -

With the above command, we have added the necessary GPG key to make sure that the downloaded packages are authentic.

3. Add the Yarn Repository

Then, we can add the Yarn repository with the following command:

echo "deb stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

4. Update System and Install Yarn on Ubuntu

Now, all we need to do is refresh the origins of the software and install Yarn on Ubuntu using APT.

sudo apt update
sudo apt install yarn nodejs

5. Check Yarn’s Version

Then, to check if the installation was successful, we can output the version that has been installed:

yarn –version


yarn init v1.15.2

And as we can see, Yarn’s installation has been successful and we’re ready for work.

How to Use Yarn on Ubuntu

The basic use of Yarn is quite simple. First of all, we have to start a new project with the following command:

yarn init project_name

Then, we will be asked some questions related to the project that will later create the .json file where the dependencies we set will be. If we want Yarn to use the default information for the file, we can press enter for each question.

To add a dependency to our project, we just use the following command:

yarn add [package]

However, it is also possible to define a specific version of a package or library as a dependency of our project.

yarn add [package]@[version]

To update a package, we use the upgrade directive and the package name. For example:

yarn upgrade [package]

We can also specify the version of the package to be updated:

yarn upgrade [package]@[version]

Also, we can remove a package from the project with the command:

yarn upgrade [package]

Finally, to install all the defined dependencies, the following command is used:

yarn install



Remember that these dependencies are defined in the packages.json file.


Developers have to use all kinds of tools that help with application development. All this improves workflow and takes up less time. In this Yarn can help a lot with Javascript dependencies of a project. As we have learned in this tutorial, the installation process is simple, same as the basic uses.

On the other hand, it is recommended that you visit Yarn’s website and consult the official documentation. This way you will have more information, and be able to use this very popular tool to its fullest potential.

Was this tutorial helpful?

The author

Edward S.

Edward is a Content Editor with years of experience in IT as a writer, marketer, and Linux enthusiast. Edward's goal is to encourage readers to establish an impactful online presence. He also really loves dogs, guitars, and everything related to space.