Yarn is the most popular package manager for the JS host, and also compatible with npm. It provides help to automate the installation, 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. Therefore, it is considered a good choice over Npm.
In this article, you will learn how to install Yarn and manage NodeJS dependencies on CentOS 8 using the command line.
First, you log in as root and open a terminal window using Ctrl + Alt + t.
Yarn installation on CentOS 8
To install yarn in CentOS 8, you must follow these steps:
Install JS Node
You will verify that the js host package is installed on your system. If it is not installed, use the following command to install on your system:
$ sudo dnf install @nodejs
Press “y” to confirm the installation of the package. After some time, the terminal will display the status “completed”, which will notify you of the successful installation of the js node in your system.
Turn on yarn storage
You enable the Yarn repository on your system and import the repository GPG key:
$ 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
The official Yarn repository provides the latest version.
Install yarn on CentOS 8
After the yarn repository is turned on, it’s time to install the yarn on CentOS 8. To do this, you must enter the following command in the terminal:
$ sudo dnf install yarn
You press “y” to enable the loading of all necessary yarn packages.
Check yarn version
After completing the installation of yarn, you can now verify the installation of the version of yarn in your system using the following command:
$ yarn –version
The installed version of the yarn will be displayed on the terminal.
Create a new project using yarn
The yarn has been successfully installed in CentOS 8, we will learn more about some useful yarn commands.
The yarn “init” command is used to create a new yarn project. The init command is executed with the project name on the terminal.
For example, if you want to create a new yarn project called my_project, you must run the following command in the terminal:
$ yarn init my_project
You can also give any other name to your project according to your requirements. The script will be displayed on the terminal, which will ask you some questions. Either you can answer, or press Enter to set the default values.
Add or Remove Dependencies
You can install or add a new package using yarn. Enter the following command to create a new package:
$ yarn add [package_name]
You can also remove the package from the yarn design dependencies. To do this, you call the yarn removal command with the package name:
$ yarn remove [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:
$ yarn set
In this article, I explained step-by-step yarn installation on CentOS 8 and project dependency management. I hope this article helps you. Using yarn, you can easily deploy projects. In case of any problems, you can leave your review through the comments.
How to install and use Yarn Node.js package manager in CentOS 8