How to Install Yarn on CentOS 8

Published on  

3 min read

Looking for other version?

Choose a different version or distribution.

How to Install Yarn on CentOS 7

In this tutorial, we will guide you through the process of installing Yarn on CentOS 8.

Introduction

If you are a web developer working with JavaScript, you must have heard about the Yarn package manager. It is a powerful tool used for managing dependencies in your Node.js projects.

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

Prerequisites

Before we start, make sure that you have the following:

  • A CentOS 8 server with a sudo-enabled user.
  • Access to a terminal
  • User privileges: root or non-root user with sudo privileges

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 Yarn's version with the following command:

yarn --version

This command will output the version of Yarn installed on your system.

Conclusion

Congratulations! You have successfully installed Yarn on your CentOS 8 system. You can now use Yarn to manage dependencies in your Node.js projects. If you are new to Yarn, check out our beginner's guide to Yarn to learn more about this powerful tool.

About the Author

Rexposed Staff

Was this helpful?