How to Install Yarn on Ubuntu 16.04/18.04

In this tutorial,we’ll show you how to install Yarn on Ubuntu 16.04 or Ubuntu 18.04 system.

What is Yarn?

Yarn is a package manager for your code. It allows you to use and share code with other developers from around the world. Yarn does this quickly, securely, and reliably so you don’t ever have to worry.

Yarn allows you to use other developers’ solutions to different problems, making it easier for you to develop your software.

Install Yarn On Ubuntu 18.04

It`s Simple 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.

Follow the steps below to install Yarn on your Ubuntu 18.04 system:

Step 1. Add the GPG Key

curl -sS | sudo apt-key add -

Step 2. Add the Yarn Repository

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

Step 3. Update the package list and install Yarn

sudo apt update
sudo apt install yarn

If you already don’t have Node.js installed on your system, the command above will install it. Those who are using nvm can skip the Node.js installation with:

sudo apt install --no-install-recommends yarn

Step 4. Check Yarn’s Version

To verify that Yarn installed successfully, run the following commands which will print the Yarn version number:

yarn --version



At the time of writing this article, the latest version of Yarn is version:1.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 18.04

Now that you have Yarn installed on your Ubuntu system, the next step is to explore some of the most common Yarn commands.

Step 1. Create a new project with the following command

yarn init project_name

The init script will ask you several questions. You can either answer or press enter to use the default values.

Once completed, the script will create a basic package.json file containing the information you provided. You can later open and edit this file.

Step 2. Add a dependency to our project

If you want to use another package in your project, you need to add it to the project dependencies. To do so, use the yarn add command followed by the package name:

yarn add [package_name]

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]

Step 3. Upgrading dependency

To upgrade a dependency use one of the following:

yarn upgrade [package_name]

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

yarn upgrade [package_name]@[version_or_tag]

The command above will update the project dependencies to their latest version according to the version range specified in the package.json file.

Step 4. Removing dependency

Use the yarn remove command followed by the package name to remove a dependency:

yarn remove [package_name]

This command will also update the project’s package.json and yarn.lock files.

Step 5. Install all the defined dependencies

To install all project dependencies,the following command is used:

yarn install




In this article,We have shown you how to install yarn on your Ubuntu 18.04 system.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.For more information about yarn visit the Yarn documentation page.

Leave a Reply