Sep 29, 2023 5 min read

How to Install Yarn on Debian 12

Install Yarn on Debian 12 with our step-by-step tutorial. Yarn is a Facebook-proposed package manager to address npm's inadequacies.

Install Yarn on Debian 12
Table of Contents

Choose a different version or distribution

Introduction

Before we begin talking about how to install Yarn on Debian 12, let's briefly understand – What is Yarn?

Yarn, which stands for Yet Another Resource Negotiator, is a package manager that was first proposed by Facebook to address npm's inadequacies. Facebook used to utilize npm as their package manager before switching to yarn, however as the amount of their project's code increased, speed and security issues arose.

Although npm's online database is acknowledged as the largest registry in the world, npm's security and performance issues pushed developers to create alternative package management. Any package manager's main function is to install packages or to fetch code from the global registry and add it to local repositories.

As Linux-based distributions have become a popular choice for operating systems all around the world. The most well-known Linux distribution is Debian, and its most recent version, Debian 12 (Bullseye), was released in August 2021.

In this tutorial, you will install Yarn on Debian 12. We will also address a few FAQs on how to install Yarn on Debian 12.

Advantages of Yarn

  1. Faster: Yarn's parallel installation and caching make it quicker than npm.
  2. Reliable: It guarantees consistent package installations by using a lockfile.
  3. Offline Mode: Yarn can work offline or with unstable internet connections.
  4. Seamless upgrades: Simplified package updates ensure smooth transitions.
  5. Increased security: Yarn incorporates checksums for package integrity, reducing the risk of compromised dependencies.

Distinctive Qualities of yarn

The following list of distinctive qualities of the yarn package manager is provided:

  • Speed: Yarn uses a parallel installation strategy, which speeds up and improves the performance of the package by installing packages parallelly. While npm will finish installing one package before going on to the next, performance latency is experienced in this circumstance.
  • Security: Yarn uses a cryptographic hashing mechanism to make sure that packages are installed securely.
  • Log: The majority of package managers strive to deliver a readable output, however, their output interfaces vary. Yarn does support producing output that is clear and readable.
  • Information about dependencies: Yarn, which was created to address npm's deficiencies, supports the "why" command, which explains the rationale for any dependency's existence.
  • Lock file: To assist in maintaining the project dependencies, yarn creates yarn.lock files each time a module is introduced.

How to Install Yarn on Debian 12

There are three popular ways to install yarn on Debian 12:

  • Using npm
  • Using PPA command
  • Using script

This section's main body will outline a step-by-step process for installing Yarn on a Debian 12 system:

Prerequisites

Several pre-installed packages are necessary for every installation; For instance, in order to obtain yarn, your system needs the following packages:

  • Curl: In Method 2, this command-line tool will be used to import the GPG key, and in Method 3, it will be used to download the yarn script.
  • Node Package Manager(npm): Before installing yarn, npm must be installed on your Debian 12.
  • Node.js: As previously stated, Node.js is a prerequisite for installing npm, which is necessary for installing yarn.

Installing yarn using npm on Debian 12

To make this installation tutorial easier to grasp, let's break it down into a number of steps:

Step 1: Update and Upgrade

By using the command listed below, you can update the Debian 12 system repository:

sudo apt update 

Step 2: Install Node.js

Node.js is pre-installed on the Debian 12 repository, thus running the command listed below will allow you to install it:

sudo apt install nodejs npm 

It is noted that npm is also installed.

To check the Node.js version:

node -v

And for npm:

npm -v

Step 3: Install yarn using npm

Once all necessary prerequisites have been met, run the following command to install yarn using npm:

sudo npm install --global yarn 

Installing yarn using PPA on Debian 12

The steps in this process are as follows:

Step 1: Import the GPG key and enable the yarn repository

Use the following command to import the GPG key from the yarn's official website:

curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null

Use the following command to add a GPG key after authentication has been completed:

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

Step 2: Install yarn

Once you've completed the previous two steps, you're ready to install yarn. However, before you do, use the following command to update the system's repository:

sudo apt update

You may now install the yarn after updating the repository by using the command:

sudo apt install yarn 

Installing yarn using yarn script on Debian 12

Using yarn script, you may use yarn to install yarn on Debian 12:

Step 1: Download the script and install the yarn

To download the script, run the command shown below. It will install a version specific to your profile and cannot be used outside your profile.

curl -o- -L https://yarnpkg.com/install.sh | bash

How to Use Yarn on Debian 12

Create a yarn initialization directory:

mkdir yarnproject
cd yarnproject

Set up the yarn package therein:

yarn init

You can add dependencies to your project using the command listed below.

yarn add [package]

Additionally, you can specify a specific package version as a dependency:

yarn add [package]@[version]

The command listed below can be used to install all requirements.

yarn
yarn install 

How to Uninstall Yarn from Debian 12

If the yarn is no longer needed on your Debian 12 system, you can remove it from your computer. Use the following command to remove the yarn from your Debian 12 installation:

sudo npm uninstall -g yarn
sudo apt remove yarn -y

FAQs to Install Yarn on Debian 12

What are the prerequisites for installing Yarn on Debian 12? 

Yarn requires Node.js to be installed on your system. Ensure you have Node.js installed before proceeding with the Yarn installation.

How can I check if Node.js is already installed on my Debian 12 system?

Run the command node --version in your terminal. If you see a version number, Node.js is already installed.

Can I use Yarn alongside npm? 

Yes, you can have both Yarn and npm installed on your system. They can coexist without any conflicts.

How can I verify if Yarn was installed successfully on Debian 12? 

Run the command yarn --version in your terminal. If it displays the version number, Yarn was installed successfully.

How can I update Yarn to the latest version on Debian 12? 

Use the command sudo apt update && sudo apt upgrade yarn to update Yarn to the latest version.

How can I clear the Yarn cache on Debian 12?

Run the command yarn cache clean to clear the Yarn cache and free up disk space on your Debian 12 system.

Conclusion

Projects have dependencies, and in order for them to function effectively, they require a piece of code. Package managers help manage these dependencies.

Many package managers, including npm and yarn, can be used for your particular needs; the latter was developed to address npm's performance and security shortcomings.

This comprehensive tutorial explains how to install yarn on a Debian 12 system. While the second way allows you to obtain yarn using the APT repository, the first technique installs yarn using npm. The last one, in contrast to the others, installs yarn via downloading yarn script.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Tutorials - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.