December 3, 2021
How to install Yarn On Debian 11

How To Install Yarn On Debian 11

On this article we will learn how to install Yarn version 1.22.15 on Debian (Bulleyes) operating system.

Introduction

Yarn is package manager based on JavaScript, compatible with npm that helps us to automate the process of installing, updating, configuring, and removing npm packages. It speed up every download package and installation process by parallelizing operations. On this article we will explain how to install Yarn on Debian 11 operating system.

Installing Yarn on Debian 11

There are at least two options to install Yarn package on the system, namely :

  1. Using Yarn repository
  2. Using Yarn script installation

Prerequisite

Before installation is started, we must first meet the necessary prerequisites, namely:

  • Debian 11 system with adequate space
  • user with root or ordinary user with root privileges

Installing Yarn Using Repository

I think the installation using the latest repository is the safe method amongst any others, because it will be using the most recent package version which is more stable and tested by the community. The installation steps will be explained in the explanation below:

  • Update system
  • Adding key and Yarn repository to our Debian 11 system
  • Installing Yarn On Debian 11
  • Verifying Yarn installation

1. Update system

By updating our Debian 11 system, it will refresh the local list of available packages software to the newer stable version. To update and upgrade Debian 11 repositories, we will use the command line:

$ sudo apt-get update
$ sudo apt-get upgrade -y

2. Adding key and Yarn repository to our Debian 11 system

We will run the following commands to add the key and Yarn repository to your Debian 11 system.

$ curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
$ 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

3. Installing Yarn

We will install Yarn by first updating the APT cache to refresh the addition of the Yarn repository in the previous step.

$ sudo apt-get update && sudo apt-get install yarn
Install Yarn on Debian 11 | Adding  Key and Yarn Repository and Install it
Install Yarn on Debian 11 | Adding Key and Yarn Repository and Install it

4. Verifying Yarn Installation

After Yarn installation was completed done, then we will verifyt it by querying its version with teh following command line :

$ yarn -v
Yarn version 1.22.15
Yarn version 1.22.15

Installing Yarn Using Script

Using Yarn installation script is easier way to install Yarn on the system, but it is not guaranteed to the the latest version. The installation will be as follow :

  • Update system
  • Install NodeJS
  • Executing Yarn Installation Script
  • Verifying Yarn Version

1. Update System

Using the following command line :

$ sudo apt-get update
$ sudo apt-get upgrade -y

2. Install NodeJS

Will be following command line belew :

$ curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -
$ sudo apt install nodejs

3. Run Yarn Installation Script

We will execute the following command line, and during installation we will be prompted and click enter to accept the permissions and continue.

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

The completed script execution will be shown below :

ramansah@otodiginet:~$ curl -o- -L https://yarnpkg.com/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    53  100    53    0     0    133      0 --:--:-- --:--:-- --:--:--   133
100  7152  100  7152    0     0   8753      0 --:--:-- --:--:-- --:--:--  8753
Installing Yarn!
> Downloading tarball...

[1/2]: https://yarnpkg.com/latest.tar.gz --> /tmp/yarn.tar.gz.1K7LTmmNTL
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    56  100    56    0     0    123      0 --:--:-- --:--:-- --:--:--   123
100    95  100    95    0     0    116      0 --:--:-- --:--:-- --:--:--   116
100   626  100   626    0     0    440      0  0:00:01  0:00:01 --:--:--   440
100 1216k  100 1216k    0     0   391k      0  0:00:03  0:00:03 --:--:--  722k

[2/2]: https://yarnpkg.com/latest.tar.gz.asc --> /tmp/yarn.tar.gz.1K7LTmmNTL.asc
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    60  100    60    0     0    983      0 --:--:-- --:--:-- --:--:--   983
100    99  100    99    0     0    868      0 --:--:-- --:--:-- --:--:--   868
100   661  100   661    0     0   1107      0 --:--:-- --:--:-- --:--:--  645k
100  1028  100  1028    0     0    656      0  0:00:01  0:00:01 --:--:--     0
> Verifying integrity...
gpg: key 1646B01B86E50310: public key "Yarn Packaging <yarn@dan.cx>" imported
gpg: Total number processed: 1
gpg:               imported: 1
gpg: Signature made Wed 29 Sep 2021 08:14:59 PM EDT
gpg:                using RSA key 6D98490C6F1ACDDD448E45954F77679369475BAA
gpg: Good signature from "Yarn Packaging <yarn@dan.cx>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg:          There is no indication that the signature belongs to the owner.
Primary key fingerprint: 72EC F46A 56B4 AD39 C907  BBB7 1646 B01B 86E5 0310
     Subkey fingerprint: 6D98 490C 6F1A CDDD 448E  4595 4F77 6793 6947 5BAA
> GPG signature looks good
> Extracting to ~/.yarn...
> Adding to $PATH...
> We've added the following to your /home/ramansah/.bashrc
> If this isn't the profile of your current shell then please add the following to your correct profile:
   
export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH"

> Successfully installed Yarn 1.22.15! Please open another terminal where the `yarn` command will now be available.
ramansah@otodiginet:~$ yarn -v
1.22.15
Install Yarn Using Script
Install Yarn Using Script

Verifying Yarn Version

After installations was completed done, then we will verify it by querying its version.

$ yarn -v

Testing Yarn

On this section, we will take a testing to know, if then Yarn that was installed is running or not. In this section, we will create a simple project and download a testing package from the internet.

  1. Create a new directory called as testyarn
  2. Initialize Yarn on new directory created
  3. Load New Package
Creating new directory
$ mkdir testyarn
$ cd testyarn/
Initiating Yarn Project

to initiate the Yarn project, we will type the command line :

$ yarn init

The completed as shown below :

ramansah@otodiginet:~$ cd testyarn/
ramansah@otodiginet:~/testyarn$ yarn init
yarn init v1.22.15
question name (otodiginet): otodiginet
question version (1.0.0):
question description (otodiginet test yarn): otodiginet test yarn
question entry point (index.js):
question repository url (otodiginet.com): otodiginet.com
question author (otodiginet): otodiginet
question license (MIT):
question private:
success Saved package.json
Done in 82.42s.
Add new Package

On this example we will add new package called as loadash, to our Yarn project, by typing command line :

$ yarn add <package_name>

The completed result as shown below :

ramansah@otodiginet:~/testyarn$ yarn add lodash@1.2.3
yarn add v1.22.15
info No lockfile found.
[1/4] Resolving packages...
Couldn't find any versions for "lodash" that matches "1.2.3"
? Please choose a version of "lodash" from this list: 4.17.20
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...

success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ lodash@4.17.20
info All dependencies
└─ lodash@4.17.20
Done in 88.32s.
Addning new Package to Yarn Project
Addning new Package to Yarn Project

Conclusion

So far, we have shown you how to install Yarn version 1.22.15 on Debian Operating system successfully. I hope that this article is useful for those of you who need it. Detail information about Yarn can be found on Yarn official web site.

Share this article via :

Leave a Reply

Your email address will not be published. Required fields are marked *