Yarn is the most popular package manager for node JS and also compatible with npm. It provides help to automate the process installation, configuration and easily removes extra npm packages. Yarn is comparatively faster than npm in terms of package installation speed and can simultaneously install various packages. So, 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 will log in as a root user and open the terminal window using Ctrl + Alt + t.
You need to execute the following steps to install yarn on CentOS 8:
You will ensure that the node js package is installed on your system. If it is not installed then use the following command to install on your system:
$ sudo dnf install @nodejs
You will enable 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
The official repository of Yarn provides the latest version.
Once the yarn repository is enabled, now it’s time to install yarn on CentOS 8. For this purpose, you will type the following command on the terminal:
$ sudo dnf install yarn
You will press ‘y’ to allow download all necessary yarn packages.
Once the installation of yarn is completed, now you can verify the installation of the yarn version on your system using the following command:
$ yarn –version
The installed version of yarn will be displayed on the terminal.
The yarn has been successfully installed on CentOS 8, we will explore more about some useful yarn commands.
The yarn ‘init’ command is used to create a new yarn project. The init command executes with the project name on the terminal.
For example, if you want to create a new yarn project named my_project then you would execute the following command on the terminal:
$ yarn init my_project
You can also give any other name to your project as per your requirements. The script will be displayed on the terminal that will ask you several questions. Either you can answer or press enter that will set the default values.
You can install or add a new package using yarn. Type the following command to create a new package:
$ yarn add [package_name]
You can also remove a package from the yarn project’s dependencies. For this purpose, you will invoke the yarn remove command with the package name:
$ yarn remove [package_name]
You can also install all dependencies of an existing project that are defined in ‘package.json’ file. Use the following command:
$ yarn
Or
$ yarn install
In this article, I have explained the step by step installation of yarn on CentOS 8 and manage project dependencies. I hope this article would help you. Using yarn you can easily deploy projects. In case of any problem, you can give your feedback via comments.
Magento is a free and open-source e-commerce platform written in PHP. It is simple, easy…
ISPConfig is an open-source control panel that allows users to manage multiple servers from a…
As a Linux administrator, you may find it necessary to troubleshoot or test your Simple…
Ubuntu 24.04, like many modern Linux distributions, relies on the NetworkManager for managing network connections.…
Restic is a modern, open-source backup program designed for efficiency, security, and simplicity. It enables…
phpMyAdmin is a popular free tool written in PHP intended to administer MySQL and MariaDB…