Open In App

How to Install Yarn on Debian 12

Last Updated : 15 Mar, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Yarn is a fast, reliable, and secure package manager for JavaScript, commonly used for managing dependencies in Node.js projects. Installing Yarn on Debian 12 is a straightforward process, but it requires adding the Yarn repository to your system’s package sources. In this comprehensive guide, we’ll walk you through the step-by-step process of installing Yarn on Debian 12.

Why Use Yarn?

Yarn offers several advantages over other package managers like npm:

  • Improved Performance: Yarn parallelizes operations to maximize resource utilization, resulting in faster package installations.
  • Predictable Dependency Management: Yarn generates a lock file (yarn.lock) to ensure consistent and reliable dependency resolution across different environments.
  • Security: Yarn provides built-in checksum verification and a robust audit system to detect and address security vulnerabilities in dependencies.

Method 1 : Using Node Package Manager (NPM)

Step 1 : Installing Node.js and Node Package Manager.

To install node package manager we will need to install npm and nodejs onto our system using following command

sudo apt install nodejs npm -y
installing-nodejs-and-npm-using-apt-package-manager

installing nodejs and npm

Once installation is done, verify it using following command

node -v
checking-npm-version

verifying npm installation

Step 2 : Install yarn

Once Node Package Manager is installed, we can install yarn using npm install command

sudo npm install --global yarn 
installing-yarn-using-npm-package

installing yarn using npm

Step 3 : Verify Installation

After installation completes, verify it using following command

yarn --version
verifying-yarn-installation

verifying yarn installation

Method 2 : Using Official Yarn PPA

Step 1 : Add yarn repository.

On Debian 12, we can install Yarn via our Debian package repository. Add Repository using following command

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
adding-yarn-ppa

adding yarn ppa

Step 2 : Installing yarn

Now, we will install yarn using APT package manager using apt install command as follows

sudo apt update && sudo apt install yarn
installing-yarn-using-APT

installing yarn using APT Package Manager

Step 3 : Verify installation

Once install finishes, verify it using yarn –version command

yarn --version
checking-yarn-version

verifying yarn installation

Uninstalling yarn :

There are two methods to uninstall yarn depending on installation method. If you have installed yarn using Node Package Manager then use following method.

Method 1 : If installed using Node Package Manager

Use npm uninstall command to remove yarn package.

npm uninstall yarn -g  
removing-yarn-using-npm

uninstalling yarn using node package manager

If you have installed yarn using PPA then use following method

Method 2 : Installed using PPA

Use apt purge command to completely remove yarn from your system.

sudo apt purge -g yarn 
removing-yarn-using-apt-package-manager

uninstalling yarn using apt package manager

How to Install Yarn on Debian 12 – FAQs

Do I need to install Node.js before installing Yarn?

Yes, Yarn depends on Node.js to function. You’ll need to have Node.js installed on your Debian system before proceeding with Yarn installation.

Is it safe to have both npm and Yarn installed on my system?

Yes, it’s safe to have both npm and Yarn coexist on your system. You can specify which package manager to use by using npm or yarn command.

I am having curn command not found issue when I try to install it using PPA method mentioned above.

This issue is caused because you don’t have curl installed in your system.

Install curl using apt install command

sudo apt install curl

Conclusion

In this article we have discussed two methods for installing Yarn on Debian 12. For most users, the recommended approach is to use the Official PPAs method for ease of installation, and not requiring Node Package Manager. With Yarn installed on your Debian 12 system, we can now manage dependencies in our JavaScript projects efficiently.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads