Yarn, also called “Yet Another Resource Navigator,” is a fast, secure and reliable JavaScript package manager that allows you to automate the installation, configuring, updating, and removing of npm packages. Yarn caches every package it has downloaded, so it never needs to download the same package again.

In this post, we will explain the following:

  • Install Yarn using NPM
  • Install Yarn from repository NPM
  • Install Yarn with Script

Step 1 – Install YARN using NPM

In this section, we will show you how to install Yarn via Node Package Manager.

First, you will need to add the NodeSource repository to your system. You can add it with the following command:

curl --silent --location https://rpm.nodesource.com/setup_18.x | bash -

Once the repository is added, install the Node.js and NPM package using the following command:

dnf install nodejs npm -y

Next, verify the Node.js version with the following command:

node --version

Sample output:

v18.19.0

You can also check the NPM version using the following command:

npm -v

Sample output:

10.2.3

Now, install the Yarn package using the NPM as shown below:

npm install --global yarn

You should get the following output:

npm notice 
npm notice New minor version of npm available! 7.21.1 -> 7.24.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v7.24.0
npm notice Run npm install -g [email protected] to update!
npm notice 

Next, verify the Yarn version with the following command:

yarn -v

Sample output:

1.22.11

You can uninstall the Yarn package from your system using the following command:

npm uninstall -g yarn

Step 2 – Install YARN from Yum Repository

In this section, we will show you how to install the Yarn package from the Rocky Linux repository. By default, the Yarn package is not included in the Rocky Linux default repository, so you will need to add the Yarn repo to your system.

First, import the Yarn repository with the following command:

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor -o /usr/share/keyrings/yarn-archive-keyring.gpg

Next, create a new file in the /etc/apt/sources.list.d/ directory to store the Yarn repository information:

echo "deb [signed-by=/usr/share/keyrings/yarn-archive-keyring.gpg] https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Finally, update the repository and install Yarn using the following command.

apt update -y
apt install yarn -y

If you want to remove the Yarn package from your system, run the following command:

dnf remove yarn -y

Step 3 – Install YARN with Script

In this section, we will show you how to install Yarn via the Yarn installation script.

You can download and run the Yarn installation script using the following command:

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

Once the Yarn package has been installed, you should get the following output:

> Successfully installed Yarn 1.22.5! Please open another terminal where the `yarn` command will now be available.

Next, activate the system path with the following command:

source ~/.bashrc

Next, verify the Yarn version using the following command:

yarn -v

Sample output:

1.22.5

Conclusion

In the above guide, we explained the three-way to install the Yarn package on RockyLinux 8. You can now use your preferred way to install the Yarn to your system. Get started with Yarn on a dedicated host from Atlantic.Net today!