Atlantic.Net Blog

How to Install Yarn NPM Package Manager on Oracle Linux 8

Yarn is a JavaScript package manager used to automate the installation, configuration, update, and removal of npm packages. Yarn stands for “Yet Another Resource Navigator.” It was developed by Facebook and is very similar to the npm package manager, with a focus on speed, security, and consistency. Yarn replaces the existing workflow of the npm client or other package managers while remaining compatible with the npm registry.

In this post, we will explain the following:

Step 1 – Install YARN using npm

First, you will need to install Node.js and npm on your server. First, list all available Node.js versions using the following command:

dnf module list nodejs

You will get the following list:

Last metadata expiration check: 0:13:42 ago on Saturday 30 April 2022 08:14:41 AM EDT.
Oracle Linux 8 Application Stream (x86_64)
Name                     Stream                     Profiles                                               Summary                            
nodejs                   10 [d][x]                  common [d], development, minimal, s2i                  Javascript runtime                 
nodejs                   12 [x]                     common [d], development, minimal, s2i                  Javascript runtime                 
nodejs                   14 [x]                     common [d], development, minimal, s2i                  Javascript runtime                 
nodejs                   16 [x]                     common [d], development, minimal, s2i                  Javascript runtime                 

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

Now, install Node.js version 16 using the following command:

dnf install @nodejs:16

Once Node.js is installed, verify the Node.js version with the following command:

node --version

Sample output:

v16.13.1

You can also check the npmversion using the following command:

npm -v

Sample output:

8.1.2

Now, use npm to install the Yarn package as shown below:

npm install --global yarn

You can verify the Yarn version with the following command:

yarn -v

Sample output:

1.22.18

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

npm uninstall -g yarn

Also Read

How to Install Node.js and NPM on Oracle Linux 8

Step 2 – Install YARN from Yum Repository

By default, the Yarn package is not included in the Oracle Linux default repository, so you will need to add the Yarn repo to your system.

First, create a Yarn repo with the following command:

curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo

Once the Yarn repo is created, install the Yarn package with the following command:

dnf install yarn -y

Once the Yarn has been installed, activate the Yarn environment variable using the following command:

source /etc/profile

Next, verify the Yarn version with the following command:

yarn -v

Sample output:

1.22.18

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

Yarn also provides a bash script that allows you to install Yarn on any Linux operating system. 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:

> GPG signature looks good
> Extracting to ~/.yarn...
> Adding to $PATH...
> We've added the following to your /root/.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.18! 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.18

Conclusion

In the above guide, we explained three-way to install the Yarn package on Oracle Linux 8. You can now use your preferred way to install the Yarn on your system. Give it a try on your dedicated server from Atlantic.Net!

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year