How to Install Yarn on Ubuntu 20.04

How to Install Yarn on Ubuntu 20.04

This is a npm compatible JavaScript package manager that helps you automate the process of installing, updating, configuring, and removing npm packages. It caches every download package and speeds up the installation process by parallelizing operations.

In this tutorial, we will explain how to install Yarn on Ubuntu 20.04. We will also go through basic Yarn orders and options.

Installing Yarn on Ubuntu

Installing Yarn on Ubuntu is quite easy. We will activate the official Thread repository, import the GPG key repository, and install packages. The repository is managed consistently and provides the most up-to-date version.

Import the GPG repository key and add the APT Thread repository to your system by running the following command:
curl -sS | sudo apt-key add -
echo "deb stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

After the repository is activated, update the package list, and install Yarn.
sudo apt update
sudo apt install yarn

The above command will also install Node.js. If you installed Node via nvm, skip installing Node.js with:

sudo apt install --no-install-recommends yarn

When finished, verify installation by printing a Yarn version:

yarn --version

The output will look like this:

Output :


The version installed on your system may differ from the one shown above.

There she is! You have successfully installed Thread on your Ubuntu machine, and you can start using it.

Use Yarn

Now that Yarn has been installed on your Ubuntu system, let’s explore some of the most common Yarn commands.

Create a new project

Start by creating a directory for your application and navigate to it:

mkdir ~/my_project && cd ~/my_project

To create a new project, run the Yarn init:

yarn init my_project

The command will ask several questions. Enter information as requested, or accept the default:

Output :

yarn init v1.22.4
question name (vagrant): Linuxize
question version (1.0.0): 0.0.1
question description: Testing Yarn
question entry point (index.js): 
question repository url: 
question author: Linuxize
question license (MIT): 
question private: 
success Saved package.json
Done in 20.18s.

After completion, the script creates a basic package.json file that contains the information provided. You can open and edit this file at any time.

Add dependencies

To add the npm package to the project dependencies, use the yarn add command followed by the package name:

yarn add [package_name]

The above command will update the package.json and yarn.lock files.

By default, when only package names are given, Thread installs the latest version. To install a specific version or tag, use the following syntax:

yarn add [package_name]@[version_or_tag]

Upgrade dependencies

To update a package, use one of the following commands:
yarn upgrade
yarn upgrade [package_name]
yarn upgrade [package_name]@[version_or_tag]

If no package name is given, the command will update the project dependencies to their latest version according to the version range specified in the package.json file. Otherwise, only the specified packages are updated.

Remove dependency

Use the Yarn remove command command followed by the package name to remove the dependency:

yarn remove [package_name]

The command will remove the package and update the project’s package.json and yarn.lock files.

Installing all project dependencies

To install all project dependencies that are specified in the package.json file, run:



yarn install


We have shown you how to install Yarn on your Ubuntu machine. For more information about Yarn visit their documentation page.

If you have any questions or feedback, feel free to comment below.

Related posts

How to Install CouchDB on Ubuntu 20.04


How to Install Android Studio on Ubuntu 20.04


How to Install Atom Text Editor on Ubuntu 20.04


How to Set Up an OpenNMS Network Monitoring Solution on Ubuntu 20.04 LTS


How to Install the SNMP Cacti Monitoring Tool on Debian 10


How to Install the GitScrum Agile Project Management Tool on Ubuntu 20.04 LTS


How to Install R on Ubuntu 20.04


How to Change SFTP Port


How to Set an SSH Key on Ubuntu 20.04