How to Install Yarn on Debian 9

Updated on

3 min read

Install Yarn on Debian 9

Yarn is a JavaScript package manager compatible with npm. It was created to solve a set of problems with the npm such as speeding up the packages installation process by parallelizing operations and reducing errors related to network connectivity.

In this tutorial, we will guide you on how to install Yarn on a Debian 9 system via the Yarn APT package repository. The official Yarn repository is consistently maintained and provides the most up-to-date version.


Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges .

Installing Yarn on Debian

Follow these step below to install Yarn on your Debian 9 system:

  1. The first step is to enable the Yarn repository. Start by importing the repository’s GPG key using the following curl command :

    curl -sS | sudo apt-key add -

    Use the following command to enable the Yarn APT repository:

    echo "deb stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
  2. Once the repository is enabled, update the package index and install Yarn, with:

    sudo apt updatesudo 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
  3. Verify the installation by printing the Yarn version number:

    yarn --version

    At the time of writing this article, the latest version of Yarn is version 1.17.3.


Using Yarn

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

Creating a new project

To create a new Yarn project use the yarn init command as shown below:

yarn init my_yarn_project

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

yarn init v1.17.3
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.

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

Adding dependency

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]

The command above will also update the package.json and yarn.lock files so anyone working on this project when running yarn will get the same dependencies.

You can also specify the package version or package tag:

yarn add [package_name]@[version_or_tag]

Upgrading dependency

To upgrade the packages, use one of the following commands:

yarn upgradeyarn 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.

Removing dependency

To remove a dependency use the yarn remove command followed by the package name:

yarn remove [package_name]

This command will also 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 Debian 9 machine. For more information about yarn visit the Yarn documentation page.

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