Atlantic.Net Blog

How to Install Yarn on CentOS 8

Yarn is an advanced package management tool released by Facebook for JavaScript applications. Yarn is mostly used for Node.js applications and is compatible with npm, meaning it can install, remove, configure and update npm packages. It was specially designed to speed up package installation process.

In this guide, we will explain different ways to install Yarn on CentOS 8.

Step 1 – Install Yarn

Install Yarn with NPM

You can install Yarn with NPM “Node Package Manager.” First, install Node.js with the following command:

dnf update -y
dnf install @nodejs -y

Once installed, you can install the Yarn package globally using the following command:

npm install yarn -g

Once installed, you should see the following output:

You can now verify the version of Yarn with the following command:

yarn -v

You should see the following output:

1.22.4

Install Yarn with Script

The simplest and easiest way to install Yarn is to install it from the script available at the Yarn official website.

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

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

Once the installation has been finished, you should see the following output:

Note: This script will install Yarn only for the current user.

Next, activate the PATH environment variable for Yarn with the following command:

source ~/.bashrc

Next, verify the Yarn version with the following command:

yarn -v

You should see the following output:

1.22.4

Install Yarn from Repository

You can also install Yarn from the official repository.

First, add the Yarn repository with the following command:

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

You should see the following output:

Next, import the Yarn GPG key with the following command:

rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg

Finally, install Yarn by running the following command:

dnf install yarn -y

Next, verify the Yarn version with the following command:

yarn -v

You should see the following output:

1.22.4

Step 2 – Yarn Basic Command-line Usage

In this section, we will show some basic commands to create and manage the Yarn project.

To create a new Yarn project, run the following command:

yarn init projectname

This will create a package.json for your project.

You can now initiate a Yarn project in your current working directory with the following command:

yarn init

To install all the dependencies for your project specified in the package.json, run the following command:

yarn install

To add any package as a dependency in your project, run the following command:

yarn add packagename

To update any package dependencies, run the following command:

yarn upgrade packagename

To remove any package from the dependencies, run the following command:

yarn remove packagename

Conclusion

Congratulations! You have successfully installed Yarn on CentOS 8. You can now use your desired method to install Yarn in your system – try it today using your Atlantic.Net VPS Hosting. For more information, visit the Yarn official documentation page.

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