
Yarn is an open-source JavaScript package manager for Node.Js. It allows to install, update, configure, and remove npm packages with multiple benefits over npm. It includes faster rate of package downloads, ability to download offline packages, reduce connectivity issues and auto-generation of lock files. This tutorial explains how to install Yarn on CentOS 8 system.
Install Yarn on CentOS
Before starting yarn installation, Make sure you have Install Node.js on your CentOS system.
Perform the following steps as root or user with sudo privileges to install Yarn on CentOS system:
Step 1 – Enable Yarn Repository
To enable yarn repository and import the repository’s GPG key , run the following commands:
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
Step 2 – Install Yarn
Once the repository is enabled, install yarn using:
sudo yum install yarn
Step 3 – Verify Installation
To verify the installation check the version by typing:
yarn --version
1.22.4
Use of Yarn
Now, yarn is installed on your CentOS system. We will some basic usage of Yarn commands:
Create a new project
You need to use yarn init
command followed by the project name to create a new Yarn project. For example, to create a project with name demo
type:
yarn init demo
You will be prompted for few questions. Give answers for it or you can skip by pressing Enter
key.
It will create a package.json
file which contains all the information which you provided.
For existing project you also can initiate yarn, navigate to directory and run:
yarn init
Adding dependency
To add a package to your project, use the yarn add
command followed by the package name:
yarn add PACKAGE_NAME
The above command will install latest version of the package and update the project’s package.json
and yarn.lock
files. For a specific version of package specify version as following:
yarn add PACKAGE_NAME@VERSION
Upgrading dependency
You can update the packages by simple use of following command:
yarn upgrade
It will update all the project dependencies to their latest version. You can specify the package name and version for specific update.
Removing dependency
To remove a package from the project’s dependencies, use the yarn remove
command followed by the package name:
yarn remove PACKAGE_NAME
Installing all project dependencies
To install all the dependencies of an existing project that are specified in the package.json
file run:
yarn install
Conclusion
We have show how to install Yarn and use of common commands on CentOS 8 machine. You can learn more about Yarn at documentation page.
If you have any questions or suggestion, leave a comment below.
Leave a Reply