Yarn (an acronym of Yet Another Resource Negotiator) is package manager initially introduced by Facebook, to overcome the deficiencies of a well-known package manager npm. Before yarn, Facebook used npm as their package manager but as soon their project’s code size grew, a speed and security problems were being faced. An online database managed by npm is recognized as world largest registry, but the security and performance concerns of npm forced developers to provide a new package manager.
Primary purpose of any package manager is to install any package or fetching the code from global registry and adding that into local repos. The installed packages do have some dependencies and these dependencies are managed by semantic versioning schema. This schema considers the impact of any change occurred in a version: like whether that change adds a new feature or fixes any bug.
As Linux-based distros have emerged as a leading operating system around the globe. Debian is most famous Linux-based distribution, and its latest release was made available in August 2021 and named as Debian 11 (Bullseye).
Keeping in view the importance of yarn and Debian 11; this post provides a detailed guide to install yarn package manager on Debian 11(Bullseye):
Before digging into the installation, let’s have a look at few notable features of yarn package manager:
Distinctive Features of yarn
This section provides list of some unique features of yarn package manager:
- Speed: yarn follows parallel pattern for installation, in which packages are installed parallelly that enhances the speed and performance of the package. Whereas npm will complete the installation of one package before moving to the next and thus performance lag is faced in this situation.
- Security: Yarn follows cryptographic hashing algorithm to ensure the secure installation of packages.
- Log: Most of the package managers focus to provide an understandable output; however, their output interface differs. Yarn do support to provide a clean and readable output.
- Dependency related information: yarn that was built to overcome the deficiencies of npm support “why” command that tells the reason for presence of any dependency.
- Lock file: Whenever a module s added, yarn generates “yarn.lock” files to help managing the project dependencies.
How to install Yarn on Debian 11
Majorly there are three methods to get yarn on your Debian 11:
- Method 1: Install yarn using npm
- Method 2: Install yarn using PPA command
- Method 3: Install yarn using script
This core part of writing will provide a step-by-step procedure to install Yarn on your Debian 11 system:
Every installation requires few pre-installed packages; For instance, your system must have the following packages to get yarn:
- Curl: This command line utility will be used in Method 2 to import the GPG key and to download yarn script in Method 3.
- Node Package Manager(npm): Your Debian 11 must be equipped with npm prior to the installation of yarn.
- Node.js: As mentioned above, npm is a core requirement to install yarn; and to install npm, your system must contain Node.js.
Method 1: How to install yarn using npm on Debian 11
Let’s break this installation guide into series of steps for better understandability:
Step 1: Update and Upgrade
Update the Debian 11system’s repo by using below mentioned command:
$ sudo apt update
Step 2: Install Node.js
By default, Node.js is present on Debian 11 repo; hence, it can be installed by using the below mentioned command:
$ sudo apt install nodejs npm
It is noticed that npm is installed as well:
To check version of Node.js
$ node -v
And for npm:
$ npm -v
Step 3: Install yarn using npm
Once the prerequisites list is completed; you can install yarn with help of npm by using the command mentioned below:
$ sudo npm install --global yarn
Method 2: How to install yarn using PPA on Debian 11
This method contains following steps:
Step 1: Import the GPG key and enable yarn repository
Import the GPG key from official yarn website by using the following command:
$ curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
Once the authentication is performed by adding GPG key; use the following command to do so:
$ 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 the above two steps are preformed; you are ready to install yarn; but first update the system’s repository with the help of following command:
$ sudo apt update
Once the repository is updated; you can now install the yarn; to do so, use the following command:
$ sudo apt install yarn
Method 3: How to install yarn using yarn script on Debian 11
This method will allow you to install yarn on Debian 11 by using yarn script:
Step 1: Download the script and install yarn
Execute the below mentioned command to download the script and it will install a profile specific version and cannot be used outside your profile.
$ curl -o- -L https://yarnpkg.com/install.sh | bash
How to use yarn on Debian 11
Make a directory for initialization of yarn:
$ mkdir yarnproject $ cd yarnproject
Initialize the yarn package in it:
$ yarn init
The command mentioned below can be used to add dependency to your project.
$ yarn add [package]
Moreover, you can also add a specific version of package as a dependency:
$ yarn add [package]@[version]
You can install all dependencies with the help of command mentioned below.
$ yarn $ yarn install
How to remove yarn from Debian 11
In case you do not require yarn anymore on your Debian 11; you can get rid of it by removing it from your system. To uninstall yarn from your Debian 11, use the following command:
$ sudo npm uninstall -g yarn
Package managers assist to manage project dependencies; projects have some dependencies, and they require piece of code to work properly. Several package managers like npm and yarn can work for your specific purpose: the latter one was introduced to cover the security and performance deficiencies of npm. This detailed post guides to install yarn on Debian 11 system. First method uses npm to install yarn whereas second method enables you to get yarn using APT repository. Contrary to these, the last one installs yarn by downloading yarn script.
The Best Linux Tutorials Website