Install YARN on Linux and Windows [Step-by-Step]


Linux

Author: Omer Cakmak
Reviewer: Deepak Prasad

YARN is an npm alternative package manager developed by Facebook and with support from Google, Exponent and Tilde engineers. Yarn promises to be better than npm for speed and security.

In this article, we will explain the installation of YARN.

Let's explain the installation steps on the successor of Centos and the Redhat-based operating system Rocky Linux, the popular Linux distribution Ubuntu and finally the Windows operating system.

 

Install YARN on Ubuntu (Debian based Linux Distributions)

Yarn can be installed with 3 different methods on Ubuntu 22.04.

 

Method-1: Install From Yarn Repository

The package list is updated:

foc@ubuntu22:~$ sudo apt update

Curl is needed to download yarn repo key:

foc@ubuntu22:~$ sudo apt install curl -y

Repo key is pulled and added into the system:

foc@ubuntu22:~$ sudo curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK

/etc/apt/sources.list.d under the repo file is created and the file information is defined:

foc@ubuntu22:~$ echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
deb https://dl.yarnpkg.com/debian/ stable main

After the newly added repo, the repo package list is updated again:

foc@ubuntu22:~$ sudo apt update

And now the yarn package is loaded:

foc@ubuntu22:~$ sudo apt install yarn -y

The command above is also Node.js. will install. If the node.js is already installed, skip the installation as follows:

foc@ubuntu22:~$ sudo apt install --no-install-recommends yarn -y

The installation was successfully completed.  Installed Yarn version:

foc@ubuntu22:~$ yarn -v
1.22.19

 

Method-2: Install From Script

The loading steps with this method are shorter than the previous method. Repo package list is updated and Curl package is installed:

foc@ubuntu22:~$ sudo apt update && sudo apt install curl -y

Then pull the install.sh script using curl, run:

foc@ubuntu22:~$ curl -o- -L https://yarnpkg.com/install.sh | bash

Yarn was founded. If you do not have Node.js installed on your system, you will get the following warning:

Yarn requires Node.js 4.0 or higher to be installed.
> Yarn was installed, but doesn't seem to be working :(.

When we want to get information about tomorrow, the following warning appears:

foc@ubuntu22:~$ yarn -h
Yarn requires Node.js 4.0 or higher to be installed.

If Node.js is already installed, it's fine. Yarn version:

foc@ubuntu22:~$ yarn -v
1.22.19

 

Method-3: Install Yarn using NPM

This step may be easier for you if you have NPM installed on your system. Or you can choose this step if you are going to use NPM.

NPM (Node Package Manager) is a package management system that Node.js accepts as a standard. npm is run from the command line and provides dependency management for applications.

If you haven't installed NPM, update the repo package list and install the npm package:

foc@ubuntu22:~$ sudo apt update && sudo apt install npm -y

NPM successfully installed, version:

foc@ubuntu22:~$ npm -v
8.5.1

Then install the yarn package with npm:

foc@ubuntu22:~$ sudo npm install -g yarn
added 1 package, and audited 2 packages in 969ms
found 0 vulnerabilities

Installed yarn version:

foc@ubuntu22:~$ yarn -v
1.22.19

 

Install YARN on Rocky Linux (Red Hat based Linux Distributions)

If you are using a Redhat based operating system (Centos, AlmaLinux, Fedora), you must follow the steps below to install Yarn.  We will explain how to install Yarn with 3 methods on Rocky Linux.

 

Method-1: Install From Yarn Repository

To pull the Yarn repo file, curl must be installed on the system:

[foc@rocky9 ~]$ sudo dnf install curl -y

The yarn.repo file is created under the /etc/yum.repos.d directory and the information is defined:

[foc@rocky9 ~]$ curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
[sudo] password for foc:
[yarn]
name=Yarn Repository
baseurl=https://dl.yarnpkg.com/rpm/
enabled=1
gpgcheck=1
gpgkey=https://dl.yarnpkg.com/rpm/pubkey.gpg

The gpg key is loaded:

[foc@rocky9 ~]$ sudo rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg

Install yarn package from newly added repo:

[foc@rocky9 ~]$ sudo dnf install yarn -y

Installed version:

[foc@rocky9 ~]$ yarn -v
1.22.19

 

Method-2: Install From Script

To install Yarn with bash script on Rocky Linux, curl must be installed on the system:

[foc@rocky9 ~]$ sudo dnf install curl tar -y

Then the script is get and the installation starts:

[foc@rocky9 ~]$ curl -o- -L https://yarnpkg.com/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 100 53 100 53 0 0 182 0 --:--:-- --:--:-- --:--:-- 182
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 100 7152 100 7152 0 0 7867 0 --:--:-- --:--:-- --:--:-- 2328k
Installing Yarn!
> Downloading tarball...

[1/2]: https://yarnpkg.com/latest.tar.gz --> /tmp/yarn.tar.gz.1J1lVy7CPV
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 100 56 100 56 0 0 191 0 --:--:-- --:--:-- --:--:-- 191
100 94 100 94 0 0 116 0 --:--:-- --:--:-- --:--:-- 116
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 --:--:-- 0:00:01 --:--:-- 0
100 1215k 100 1215k 0 0 641k 0 0:00:01 0:00:01 --:--:-- 641k

[2/2]: https://yarnpkg.com/latest.tar.gz.asc --> /tmp/yarn.tar.gz.1J1lVy7CPV.asc
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 100 60 100 60 0 0 769 0 --:--:-- --:--:-- --:--:-- 75100 60 100 60 0 0 769 0 --:--:-- --:--:-- --:--:-- 759
100 98 100 98 0 0 759 0 --:--:-- --:--:-- --:--:-- 759
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 833 100 833 0 0 2313 0 --:--:-- --:--:-- --:--:-- 2313
> Verifying integrity...
gpg: key 1646B01B86E50310: public key "Yarn Packaging <yarn@dan.cx>" imported
gpg: Total number processed: 1
gpg: imported: 1
gpg: Signature made Tue 10 May 2022 10:48:23 PM +03
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/foc/.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.19! Please open another terminal where the `yarn` command will now be available.

Exit the terminal you're installing from and login:

[foc@rocky9 ~]$ yarn -v
1.22.19

If the system does not have Node.js, you will get the following warning, but Yarn will be successfully installed.

Yarn requires Node.js 4.0 or higher to be installed.
> Yarn was installed, but doesn't seem to be working :(.

 

Method-3: Install Yarn using NPM

If you have NPM installed on your system, this step may be easier for you. If you want to install npm, run the following command in terminal:

[foc@rocky9 ~]$ sudo dnf install npm -y

Install the yarn package with NPM:

[foc@rocky9 ~]$ sudo npm install --global yarn

added 1 package, and audited 2 packages in 1s

found 0 vulnerabilities
npm notice
npm notice New minor version of npm available! 8.15.0 -> 8.19.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.19.2
npm notice Run npm install -g npm@8.19.2 to update!
npm notice

Installed version:

[foc@rocky9 ~]$ yarn -v
1.22.19

 

Install YARN on Windows

This step will assist you in installing Yarn on the Windows operating system. Download the setup file for Windows from the Yarn official website.

install YARN

 

Double-click the downloaded file and start the installation.

Install YARN on Linux and Windows [Step-by-Step]

 

Proceed by accepting the license terms.

Install YARN on Linux and Windows [Step-by-Step]

 

Specify the installation directory, it is recommended to remain the default.

Install YARN on Linux and Windows [Step-by-Step]

 

Click the Install button.

Install YARN on Linux and Windows [Step-by-Step]

 

Complete the installation with the Finish button.

Install YARN on Linux and Windows [Step-by-Step]

 

Installation completed successfully. You can check the installed Yarn version from the cmd screen.

Install YARN on Linux and Windows [Step-by-Step]

 

Summary

We reviewed Yarn installation steps for 3 different operating systems. We have installed for 2 different distribution types, especially in Linux distributions. You can use this guide for Linux distributions of the same type (Ubuntu=Debian=Pardus etc).

For more information about Yarn, you can visit the Yarn Official website.

 

References

classic.yarnpkg.com - Installation

 

Omer Cakmak

Omer Cakmak

He is highly skilled at managing Debian, Ubuntu, CentOS, Oracle Linux, and Red Hat servers. Proficient in bash scripting, Ansible, and AWX central server management, he handles server operations on OpenStack, KVM, Proxmox, and VMware. You can connect with him on his LinkedIn profile.

Can't find what you're searching for? Let us assist you.

Enter your query below, and we'll provide instant results tailored to your needs.

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can send mail to admin@golinuxcloud.com

Thank You for your support!!

Leave a Comment