How to Install Yarn on CentOS 7

Install Yarn on CentOS 7

Yarn is a advanced package management tool for Javascript applications mostly used for Node.js applications. Yarn is compatible with npm used for installing, configuring, updating and removing npm packages. It helps to solve problems with npm like network connectivity issues, speeding up the installation process etc. In this tutorial we are going to install Yarn on CentOS 7.


Before you start to install Yarn on CentOS 7. You must have the non-root user account on your system with sudo privileges.

Install Yarn on CentOS 7

First check if Nodejs is installed on your system running following command:

node --version

If Node.js is not installed run following commands to install it:

sudo yum install nodejs

Update Nodesource repository using following curl command:

curl --silent --location | sudo bash -

Install Node.js typing following in the terminal:

sudo yum install nodejs

To install Yarn first import the GPG key to enable Yarn repository using curl command:

curl --silent --location | sudo tee /etc/yum.repos.d/yarn.repo
sudo rpm --import>

To install Yarn run following command in the terminal and hit ENTER:

sudo yum install yarn

Now confirm installation and check version of Yarn using following command:

yarn --version

The output should look like:


Eaxamples of Using Yarn

Create a new Project

You can create new project using Yarn running following command. This command will also ask you some questions please press ENTER to use default values or type answer.

sudo yarn init new_project

NOTE: Now it will create package.json file saving information provided by you. You can also edit the information inside file anytime.

The above command output should look like:

yarn init v1.13.0
question name (vagrant): Linux4one
question version (1.0.0): 0.0.1
question description: Testing Yarn
question entry point (index.js): 
question repository url: 
question author: Linux4one
question license (MIT): 
question private: 
success Saved package.json
Done in 17.56s.

Install all dependencies

To install all the dependencies given inside package.json file use following command

yarn install

The above command will install all the dependencies given in package.json file.

Add dependency

Following is the basic syntax for adding dependency:

yarn add [package_name]
yarn add [package_name]@[version_number_or_tag_name]

The above command will add dependency to your project updating yarn.lock and package.json files.

Remove dependency

following is the basic syntax for removing dependency:

yarn remove [package_name]

The above command removes specific dependency from your project updating yarn.lock and package.json files.

Update dependency

The basic syntax for upgrading dependency is given below:

yarn upgrade [package_name]
yarn upgrade [package_name]@[version_number_or_tag_name]

The above command will upgrade specific package to latest version in your project then updates yarn.lock and package.json files.


You have successfully learned how to install Yarn on CentOS 7. If you have any queries regarding this then please dont forget to comment below.