Yarn is the most popular package manager for Node JS and is also compatible with npm. It provides help in automating process installation and configuration, and easily removes additional npm packages. Yarn is comparatively faster than npm in terms of package installation speed and can install different packages at the same time. It is therefore considered a good choice over npm.
This article shows you how to install Yarn and manage NodeJS dependencies on CentOS 8 from the command line.
First, log in as the root user and open the terminal window with Ctrl + Alt + t.
Installation of yarn on CentOS 8
You need to follow the steps below to install yarn on CentOS 8:
Install node js
You make sure that the node js package is installed on your system. If it isn’t installed, use the following command to install it on your system:
$ sudo dnf install @nodejs
Press ‘y’ to confirm the installation of the package. After a while, the status ‘complete’ will be displayed on the terminal, informing you that node js has been successfully installed on your system.
Activate the yarn repository
You activate the Yarn repository on your system and import the GPG key of the repository:
$ 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
Yarn’s official repository has the latest version.
Install Yarn on CentOS 8
Once the yarn repository is activated, now is the time to install yarn on CentOS 8. To do this, enter the following command on the terminal:
$ sudo dnf install yarn
You will press ‘y’ to allow all required yarn packages to be downloaded.
Check yarn version
Once the installation of yarn is complete, you can now verify the installation of the yarn version on your system with the following command:
$ yarn –version
The installed yarn version is displayed on the terminal.
Create a new project with yarn
The yarn was successfully installed on CentOS 8. We’ll learn more about some useful thread commands.
The yarn ‘init’ command is used to create a new yarn project. The init command is executed on the terminal with the project name.
For example, if you want to create a new yarn project called my_project, run the following command on the terminal:
$ yarn init my_project
You can also give your project a different name according to your requirements. The script will appear on the terminal asking you several questions. You can either reply or press Enter to set the default values.
Add or remove dependencies
You can install or add a new package of yarn. Enter the following command to create a new package:
$ Add yarn [package_name]
You can also remove a package from the thread project’s dependencies. To do this, invoke the Remove yarn command with the package name:
$ Remove the thread [package_name]
You can also install all the dependencies of an existing project that are defined in the ‘package.json’ file. Use the following command:
In this article I have explained how to install yarn on CentOS 8 step by step and how to manage project dependencies. I hope this article will help you. Using yarn makes it easy to deploy projects. If you have any problems, you can give your feedback via comments.