How to Install Yarn on CentOS 7

Published on  

3 min read

Looking for other version?

Choose a different version or distribution.

How to Install Yarn on CentOS 7

In this guide, we'll walk you through the steps to install Yarn on CentOS 7

Introduction

If you're a web developer working on CentOS 7, you might want to consider using Yarn as your package manager.

Yarn is the most popular node JS package manager that is also compatible with npm. It assists in automating the installation, configuration, and removal of superfluous npm packages. Yarn is faster than npm in terms of package installation speed and can install several packages at the same time. As a result, it is preferred over npm.

The installation procedure is relatively identical to other CentOS vesions, as well as Fedora and RHEL distributions.

Step 1: Update Your System

Before we begin, let's make sure that our system is up to date. Open a terminal window and run the following command:

sudo yum clean all && sudo yum -y update

This command will update the package list and upgrade any outdated packages on your system.

Step 2: Install Node.js

Yarn is built on top of Node.js, so you'll need to install it before you can install Yarn. Run the following command to install Node.js:

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

Install the Node.js package by typing:

sudo yum install nodejs

Step 3: Install Yarn

Now that we have Node.js installed, we can install Yarn. There are two ways to install Yarn on CentOS 7: using the official Yarn repository, or using npm.

Option 1: Installing Yarn from the Official Repository

To install Yarn from the official repository, run the following commands:

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

Next, add the GPG key using rpm command.

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

Then simply run this command to install Yarn:

sudo yum install yarn

Option 2: Installing Yarn using npm

If you prefer to install Yarn using npm, you can run the following command:

sudo npm install -g yarn

This will install Yarn globally on your system.

Step 4: Path Setup (Optional)

If Yarn is not found in your PATH, follow these steps to add it and allow it to be run from anywhere.

Note: your profile may be in your .profile.bash_profile.bashrc.zshrc, etc.

  1. Add this to your profile: export PATH="$PATH:/opt/yarn-[version]/bin" (the path may vary depending on where you extracted Yarn to)
  2. In the terminal, log in and log out for the changes to take effect

Step 5: Verify the Installation

Once the installation is complete, you can verify that Yarn is installed by running the following command:

yarn --version

If Yarn is installed correctly, you should see the version number printed in the terminal.

Conclusion

In this guide, we showed you how to install Yarn on CentOS 7. Yarn is a powerful tool that can help manage your Node.js dependencies and streamline your Node.js development workflow. If you're interested in learning more about Yarn, check out the official Yarn website or our guide to getting started with Yarn.

About the Author

Rexposed Staff

Was this helpful?