How to Install Yarn on CentOS 8

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

Qadry
unixcop Admin

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

You might also likeRELATED

How to set PassivePortRange and PassiveIP in pure-ftpd on Ubuntu to secure the app!

Introduction Hi guys, We will talk about setting PassivePortRange and PassiveIP in pure-ftpd. If you run a firewall on your Linux server and want to...

Install Java 8 on CentOS 8

Hi Guys, In this guide, we’ll show you how to install Oracle’s Java 8 programming language on CentOS 8 . It's an object-oriented language...

How to install flameshot on RHEL/CentOS using Snapcraft

In this post, you will learn how to install Flameshot on RHEL / CentOS Flameshot is a powerful open source screenshot and annotation tool for...