Install and Use Yarn on Debian 11

In this tutorial, we want to teach you to Install and Use Yarn on Debian 11.

Yarn is an npm-compatible JavaScript manager that aids in the automation process of setting up, updating, configuring, and removing npm packages. NPM is an abbreviation for Node Package Manager. It is an install manager for the Node JS platform. NPM is well-known as the world’s most extensive software registry. And as such, open-source DevOps across the globe utilize it to publish and share their source code.

Steps To Install and Use Yarn on Debian 11

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Debian 11.

Debian 11 – Node.js Installation

To install Yarn, you must install Node.js on your server. First, update your local package index with the following command:

sudo apt update

Then, install the required packages on your server by running the command below:

sudo apt install software-properties-common apt-transport-https wget ca-certificates gnupg2 gcc make g++ curl -y

Next, import the NodeSource repository that suits your needs in either the current release or the LTS version to install both packages:

# curl -fsSL | sudo -E bash -
# curl -fsSL | sudo bash -

Add Yarn GPG Key and Repository on Debian 11

Now that you have the Node.js repo on your server, you can start to install Yarn on your server.

First, import the Yarn package manager GPG key:

curl -sL | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null

Then, import the Yarn repository:

echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Run the system update:

sudo apt update

Install Yarn Package Manager on Debian 11

At this point, you can simply install Yarn and Node.js on your server. To do this, run the command below:

sudo apt install yarn nodejs -y

Verify your Yarn installation by checking its version:

yarn -v

Also, you can use the command below instead:

apt-cache policy yarn
  Installed: 1.22.19-1
  Candidate: 1.22.19-1
  Version table:
 *** 1.22.19-1 500
        500 stable/main amd64 Packages
        500 stable/main all Packages
        100 /var/lib/dpkg/status
     1.22.18-1 500
        500 stable/main amd64 Packages
        500 stable/main all Packages
     1.22.17-1 500
        500 stable/main amd64 Packages
        500 stable/main all Packages
     1.22.15-1 500
        500 stable/main amd64 Packages
        500 stable/main all Packages
     1.22.13-1 500
        500 stable/main amd64 Packages
        500 stable/main all Packages

Create a Sample Project with Yarn Command

At this step, we will show you how to use Yarn by creating a new project and adding/removing dependencies.

To create a new Yarn project, you can use the yarn init command.

Here we create a project named my_project, you can choose another name for it:

yarn init my_project

This command will ask you some questions. Press enter to accept the defaults or fill them with your answers.

This will look like this:

yarn init v1.22.19
question name (root): orca
question version (1.0.0):
question description: sample project
question entry point (index.js):
question repository url:
question author:
question license (MIT):
question private:
success Saved package.json
Done in 29.85s.

This command will create a basic package.json file that contains the information you have provided.

You can modify this file any time you want.

Also, you can initiate a Yarn project in an existing directory on Debian 11. To do this, switch to the directory and run the following command:

yarn init

To add a package as a dependency to your project you can use the following command:

yarn add [package_name]

With this command, you can install the package and any packages that it depends on. Also, it will update the project’s package.json and yarn.lock files.

If you use only the package name in the command, Yarn will install it in the latest version.

To install a specific version or tag, use the following command:

yarn add [package_name]@[version_or_tag]

Also, you can upgrade the packages with 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.

To remove a package from your project dependency you can use the Yarn remove command on Debian 11:

yarn remove [package_name]

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

In an existing project, you can install all dependencies that are specified in the package.json file with the following command:


Or you can use:

yarn install


At this point, you have learned to Install and Use Yarn on Debian 11.

Hope you enjoy it, you may be like these articles on the Orcacore website:

Fix sort_buffer_size for Cacti

Install Apache Kafka on Debian 11

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!