In this walkthrough, you will learn how to install Yarn on Rocky Linux 8 / AlmaLinux 8.
Step 1: Install Node.JS and NPM
To set sail, we need to install NPM as a prerequisite for Yarn installation. To achieve this, we will install NodeJS which provides the npm package. At the moment, Node.JS 16 is the latest version of Node and can be installed from Nodesource.
So, login as a sudo user and download and run the Nodesource script.
$ curl -sL https://rpm.nodesource.com/setup_16.x | sudo -E bash -
The script inspects your system’s architecture, confirms if it supports Node.JS, and proceeds to install the Nodesource repository on your system.
At the very end of the output, some post installations instructions will be displayed as shown.
$ sudo dnf install nodejs
Once installed, verify that NodeJS is installed:
$ node -v
And npm as well.
$ npm -v
Great! The prerequisite packages have been installed. The next step will be to install Yarn.
Step 2: Install Yarn on Rocky Linux
To install Yarn, proceed and add the Yarn repository to Rocky Linux as shown.
$ curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
Then install Yarn from the Yarn repository:
$ sudo dnf install yarn
When prompted, accept the GPG key by pressing ‘y’.
When the installation is complete, confirm that Yarn is installed by checking its version.
$ yarn -v
The output below confirms that we have successfully installed Yarn version 1.22.5.
A much simpler way of installing Yarn is by downloading and running an installation script as shown.
$ curl -o- -L https://yarnpkg.com/install.sh | bash
At the very end, you should see the confirmation that the installation of Yarn went along successfully.
And that’s it, guys. We have walked you through 2 ways of installing Yarn on Rocky Linux. Any of those methods will work seamlessly to ensure that Yarn is installed on your system.