How to Install Yarn on Ubuntu 20.04

Published on  

4 min read

Looking for other version?

Choose a different version or distribution.

How to Install Yarn Package Manager on Ubuntu 20.04

In this guide, we'll walk you through the steps to install Yarn on Ubuntu 20.04 LTS (Focal Fossa)


If you're a web developer working on Ubuntu 20.04 (Focal Fossa), you might want to consider using Yarn as your package manager. Yarn is a faster, more reliable alternative to npm, and it can help you manage your JavaScript packages with ease.

Step 1: Update Your System

Before we begin, let's make sure that our system is up to date. Open a terminal window and run the following command:

sudo apt update && sudo apt upgrade

This command will update the package list and upgrade any outdated packages on your system.

Step 2: Install Node.js

Yarn is built on top of Node.js, so you'll need to install it before you can install Yarn. Run the following command to install Node.js:

sudo apt install nodejs

Step 3: Install Yarn

Now that we have Node.js installed, we can install Yarn. There are two ways to install Yarn on Ubuntu 20.04: using the official Yarn repository, or using npm.

Option 1: Installing Yarn from the Official Repository

To install Yarn from the official repository, run the following commands:

curl -sS | sudo apt-key add -
echo "deb stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Then simply run this command:

sudo apt update && sudo apt install yarn

If using nvm you can avoid the node installation by doing:

sudo apt update && sudo apt install --no-install-recommends yarn

Note: Ubuntu versions may come with cmdtest installed by default. If you’re getting errors from installing yarn, you may want to run first before installing Yarn:

sudo apt remove cmdtest

Option 2: Installing Yarn using npm

If you prefer to install Yarn using npm, you can run the following command:

sudo npm install -g yarn

This will install Yarn globally on your system.

Step 4: Path Setup (Optional)

If Yarn is not found in your PATH, follow these steps to add it and allow it to be run from anywhere.

Note: your profile may be in your .profile.bash_profile.bashrc.zshrc, etc.

  1. Add this to your profile: export PATH="$PATH:/opt/yarn-[version]/bin" (the path may vary depending on where you extracted Yarn to)
  2. In the terminal, log in and log out for the changes to take effect

To have access to Yarn’s executables globally, you will need to set up the PATH environment variable in your terminal. To do this, add export PATH="$PATH:`yarn global bin`" to your profile, or if you use Fish shell, simply run the command set -U fish_user_paths (yarn global bin) $fish_user_paths

Step 5: Verify the Installation

Once the installation is complete, you can verify that Yarn is installed by running the following command:

yarn --version

If Yarn is installed correctly, you should see the version number printed in the terminal.


In this guide, we walked you through the steps to install Yarn on Ubuntu 20.04 LTS (Focal Fossa). Whether you choose to install Yarn from the official repository or using npm, Yarn is a powerful tool that can help streamline your JavaScript development workflow. If you're interested in learning more about Yarn, check out our Yarn tag on or our beginner's guide to Yarn for more information.

About the Author

Rexposed Staff

Was this helpful?