Install Yarn on Centos 8
Yarn is a package management tool for Javascript applications mostly used for Node.js applications. Yarn is mostly used for Node.js applications and is compatible with npm,used for installing,removing, configuring and update npm packages.
Yarn is is much faster than npm and it caches every package it downloads. so it never needs to download it again. It also parallelizes operations to maximize resource utilization so install times are faster than ever.
In this Tutorial, we will see how to install yarn on Centos 8.
Install yarn using npm
First we will install nodejs and make sure that your system is up to date.
sudo dnf update
sudo dnf install nodejs
once nodejs is installed,you can check the version using below command.
node --version
output:
[root@localhost ~]# node --version
v10.21.0
After installing nodejs,you can install yarn with npm using below command.
npm install yarn -g
you can also install yarn using official repository.
Also Read -> How to Install Gradle on Centos 8
Install yarn using Repository
First we need to enable yarn repository and import the repository’s GPG key.
sudo rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo -o /etc/yum.repos.d/yarn.repo
once you added yum repository, execute following command to install yarn
sudo dnf install yarn
now check yarn version
yarn --version
output:
[root@localhost ~]# yarn --version
1.22.5
Basic commands
you can create new project using yarn init.
yarn init projectname
output:
[root@localhost ~]# yarn init my_project
yarn init v1.22.5
question name (root):
question version (1.0.0):
question description:
question entry point (index.js):
question repository url:
question author:
question license (MIT):
question private:
success Saved package.json
Done in 3.84s.
now you are able to see package.json file in your project files.
To install all the dependencies of an existing project that are specified in the package.json file, run the following command.
yarn install
To add a package to your project,then use 'yarn add' command as below.
yarn add package_name
The above command will install latest version of the package. For a specific version of package you have to use along with version.
yarn add package_name@version
To update and remove package dependencies, run the following commands.
yarn upgrade package_name
yarn remove package_name
That's it. now you have successfully learned how to install yarn on CentOS 8.
Also Read -> How to Install Apache Ant on Centos 8