Ultimate Guide For Yarn Installation on Debian 12

This article intends to teach you an Ultimate Guide For Yarn Classic Installation on Debian 12. Yarn is a package manager for JavaScript, created by Facebook. You can consider it as an alternative to npm (Node Package Manager) for managing dependencies in JavaScript projects. It is used for installing, updating, and managing packages by providing a faster and more reliable solution. Also, it offers an amazing feature which is offline installation.

Now you can follow the steps below to learn a Quick and Easy Yarn Installation on Debian 12.

Yarn Installation Tutorial for Debian 12

Before you start the Yarn setup on Debian 12, you must log in to your server as a non-root user with sudo privileges. To do this, you can check the Initial Server Setup with Debian 12.

Then, follow the steps below to install and use Yarn on Debian 12.

Step 1 – Set up Node.js for Yarn Installation

First, you must run the system update with the command below:

sudo apt update

Then, install the required packages with the following command:

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

At this point, you must add and install the latest Node.js for the Yarn installation on Debian 12. To do this, you can run the following commands:

# curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo bash -
# sudo apt install nodejs -y

Verify your Node.js installation by checking its version:

nodejs --version
Output
v20.11.1

Step 2 – Add Yarn Repository on Debian 12

At this point, you must add the Yarn GPG key and repository on Debian 12. To do this, you can run the following commands:

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

# 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

Once you are done, run the system update:

sudo apt update

Step 3 – Quickly Install Yarn Package Manager on Debian 12

At this point, you can easily run the command below to install Yarn on Debian 12:

sudo apt install yarn -y

Verify your Yarn installation by checking its version:

yarn --version
Output
1.22.19

Also, you can verify it by using the following command:

sudo apt-cache policy yarn
Quickly Install Yarn Package Manager on Debian 12

Step 4 – Start Using Yarn Package Manager

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:

Start Using Yarn Package Manager

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 12. 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 12:

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:

$ yarn
Or 
$ yarn install

For more information and migration to the latest versions, you can visit the official website.

Conclusion

In conclusion, Yarn is widely used in the JavaScript community for its performance, reliability, and developer-friendly features. At this point, you have learned Yarn Classic installation on Debian 12. Hope you enjoy it.

Also, you may like to read the following articles:

Install build-essential Package in Debian Linux

Install and Use Yarn on Debian 11

Set up Yarn on AlmaLinux 9

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!