CentOS

How to Install Yarn on CentOS 8

Yarn is a very popular javascript package manager for NodeJS based projects, and it is used for managing project dependencies like installing a new package, updating a package, and efficiently removing a package. It is fully compatible with the NPM and manages packages comparatively better and faster than the older NPM package manager, leading it to be the next first choice package manager for NodeJS applications instead of NPM.

Its parallel processing enhances the installation speed and reduces the chances of getting errors due to network connection problems. This post’s purpose is to help you in installing Yarn on the CentOS 8 Operating System.

Prerequisite

The only requirement is that you should have Node installed on your CentOS 8 system.

But if you have not installed it on your system, first, ensure that the EPEL repository is enabled on your system using the command given below because the Node Js is available through the EPEL repository:

$ sudo dnf install epel-release

Now install Node using the command given below:

$ sudo dnf install @nodejs

After installing Node and fulfilling the only prerequisite, the first step is to add the Yarn repository to the CentOS 8 system.

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

After adding, Import the GPG keys of the Yarn repository as well using the command:

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

By adding the yarn repository, you will have the latest and up-to-date version of Yarn.

Install Yarn

To install Yarn on CentOS 8 after adding and importing the GPG keys, type the command given below to begin the installation:

$ sudo dnf install yarn

After the successful installation of yarn on the system, verify the installation using the command typed below:

$ yarn --version

It is witnessed that version 1.22.8 of Yarn is successfully installed and can manage the project dependencies.

Usage of Yarn

Let’s learn some basic yarn usage and see how it can be used to help in a development project.

Create a new project using Yarn

To create a new project using the Yarn command, the command given below can be used:

$ yarn init project_name

The above command will ask a couple of questions, so answer each question accordingly, and all the provided information will be saved in a package.json file to which you can edit anytime later.

Add a new package using Yarn

To add a new package or a dependency of your project, you can type the command given below:

$ yarn add package_name

Remove a package using yarn

To remove a package or dependency, type the command:

$ yarn remove package_name

Upgrade a package or packages using Yarn

To upgrade all the package or dependencies of the project, type the command given below:

$ yarn upgrade

If you want to upgrade a single package or dependency, then you can append the package name to the ‘yarn upgrade’ command as shown in the command below:

$ yarn upgrade package_name

Install all packages or dependencies of the project using Yarn

When you migrate the application to another place, you don’t need to move all the node modules along with that, you can just get your project files along with the package.json file, and you are all ready to take the project to any place.

After migrating your project to any other place like a directory or some other system, you just need to run the command given below, and it will install all the project dependencies written in the package.json file.

$ yarn install

All the dependencies will be downloaded and installed in a couple of minutes, depending upon the size of packages and internet speed.

Conclusion

This is how you can install and start using Yarn, the CentOS 8 Operating system. This post provides a brief and profound knowledge of installing and using yarn to install, remove, upgrade, and install all packages or project dependencies using Yarn on the CentOS 8 Operating system.

About the author

Sam U

I am a professional graphics designer with over 6 years of experience. Currently doing research in virtual reality, augmented reality and mixed reality.
I hardly watch movies but love to read tech related books and articles.