• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install Yarn on CentOS 7

Written by Admin, Updated On July 18, 2019
centos, nodejs, npm, yarn
How to Install Yarn on CentOS 7

Yarn is a package management tool for Javascript which mostly used for Node.js applications. Yarn is compatible with npm used for installing, configuring, updating and removing npm packages. It is designed to fix npm problems like speeding up installation process, network connectivity issues, etc. In this tutorial, you will learn how to install Yarn on CentOS 7 machine.

Prerequisites#

You should have logged in on CentOS 7 system with non-root user with sudo privileges.

Install Yarn on CentOS#

Follow the below steps to install Yarn on CentOS 7 system. At first, check that Node.js is installed or not by typing:

node --version

If not installed then update Nodesource repository using following curl command:

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

After that, run below command to install Node.js:

sudo yum install nodejs

To install Yarn, you need to add and enable Yarn repository to your system then install Yarn. You can import Yarn repository’s GPG key using below curl command:

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

Now you can install Yarn by typing below command:

sudo apt install yarn

Verify the installation of yarn by issuing below command:

yarn --version

It should show like as below:

Output
1.13.0

Use of Yarn#

Create a new Project#

You can create a new project using yarn init command as given below:

yarn init new_yarn_project

It will be prompted to you few questions. You can provide information if you want otherwise you can skip by just hitting Enter key for all the questions.

Once all the questions are completed then it will create a package.json file with the information which you provided. You also can make changes manually to that file.

Install All Dependencies#

To install all project dependencies that are given in the package.json file run:

yarn install

or you can run just yarn as below:

yarn

Adding dependency#

When you have requirement to install another package in your project then you need to add it to the project dependencies. Below is the basic syntax to add dependency:

yarn add [package_name]

This command will update the package.json file yarn.lock file. When you want specific version of any package then you can followed by version number as following:

yarn add [package_name]@[version_or_tag]

Upgrading dependency#

You can upgrade a dependency using any one of the following command:

yarn upgrade [package_name]

or

yarn upgrade [package_name]@[version_or_tag]

It will update specific package and make changes in package.json and yarn.lock file.

Removing dependency#

To remove a dependency using yarn use below command:

yarn remove [package_name]

Same as add and update command this will also update the project’s package.json and yarn.lock files.

Conclusion#

Here, we described how you how to install yarn on CentOS 7 system. You can get more details about yarn at Yarn Documentation page.

If you have any query or suggestion you can comment below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Setup Cron Job on Ubuntu 18.04
Next Article   How to Install Go on Ubuntu 18.04

Related Posts

  • How to Install Php 8 on CentOS 8

    How to Install PHP 8 on CentOS 8

    January 27, 2021
  • How to Install Python 3.9 on CentOS 8

    How to Install Python 3.9 on CentOS 8

    December 31, 2020
  • How to Install GIMP 2.10 on CentOS 8

    How to Install GIMP 2.10 on CentOS 8

    December 30, 2020

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Jenkins on Debian 11
    How to Install Jenkins on Debian 11 January 5, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook