Introduction
Yarn is a new JavaScript package manager that aims to be speedy, deterministic, and secure. See how easy it is to drop yarn in where you were using npm before, and get faster, more reliable installs.
It was created to solve a set of problems with npm, such as speeding up the packages installation process by parallelizing operations and reducing errors related to network connectivity.
In this tutorial, we will show you how to install Yarn in CentOS 8.
Installation of Yarn
Just follow the steps below to get start with yarn:
- Install the Node.js package with running the command below
dnf install @nodejs -y
- Enable the Yarn repository
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
- Import the repository’s GPG key with running the command
rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg
- Install Yarn
dnf install yarn -y
- Verify the installation by checking the Yarn version
yarn --version
Using Yarn
We’ll illustrate some of the Yarn commands in this section.
Create a new project
Use the yarn init command followed by the project name to create a new project with yarn.
For example:
yarn init unixcop_project
The script will ask you some questions as follows
The command will create a basic package.json file containing the information you provided.
NOTE: You can also initiate a Yarn project in an existing directory. to do that, navigate to the directory and execute the yarn inint command
yarn init
Add dependency
Run yarn add followed by the package name to add a package as a dependency to the project
yarn add [package name]
The command will install the package and update the project’s package.json and yarn.lock files.
NOTE: To install a specific version or tag for the packages update, use the syntax belwo:
yarn add [package name]@[version or tag]
Upgrade dependencies
To upgrade the packages, run the following commands below:
yarn install
yarn upgrade
yarn upgrade [package name]
yarn upgrade [package name]@[version or tag]
Remove dependency
To remove a package from the project’s dependencies, run
yarn remove [package name]
The files package.json and yarn.lock files will be also updated with the removed packages
Install dependencies
Just run yarn command to install all the dependencies of your project
yarn
OR
yarn install
Conclusion
That’s it
In this tutorial, We illustrated how to install yarn in CentOS 8 and showed you some of yarn commands.
Also you can install yarn on Ubuntu by visiting this link >> How to install Yarn on Ubuntu 20.04
Thanks