Tutorial How To Install Yarn On CentOS 8 Linux. Created by Facebook, join us to learn install Yarn on CentOS 8 server. In this article, you will learn about the coolest and latest package manager for NodeJS which has come to replace npm. While npm works just okay, Yarn ships with some improvements that give it a competitive edge over npm. In fact, developers are now migrating their Node.JS projects over to Yarn.
Firstly, Yarn dwarfs npm in terms of speed of package installation. Yarn is much faster than npm and installs packages simultaneously making it a better choice than npm.
And also, when a package is installed, a global cache is installed containing all the dependencies. This does away with the need to going back online to download them again and makes subsequent installation much faster.
Secondly, Yarn is considered more secure than npm. This is because it installs packages from the package.json or yarn.lock files.
Additionally, Yarn.lock guarantees that the same package is installed across all the devices thereby keeping away bugs arising from the installation of different versions. In contrast, npm installs packages from dependencies that raise security concerns due to inconsistencies in the package versions installed.
Table of Contents
How To install Yarn On CentOS 8
Let’s start with this guide to be an expert at How to install Yarn on CentOS 8. To make your study more useful, contact the Eldernode team as a VPS provider to have your own Linux Virtual Server. In case you need the guidance of the previous version, find our article on How To Install Yarn On CentOS 7.
1- How To Install NodeJS In CentOS 8
Log in to your CentOS 8 system as a root user and install the EPEL repository.
yum install epel-release
Use the following command to install NodeJS on CentOS 8.
yum module install nodejs
Run the command below to confirm the installation of Node.JS.
node -v node --version
2- How To Enable Yarn Repository
Once the Node.js is installed, you need to enable the Yarn repository.
curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo
Then, to add the GPG key:
rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg
3- How To Install Yarn in CentOS 8
Use the command below to install Yarn.
yum install yarn
To check the version of Yarn that you have installed:
yarn --version 1.21.1
4- How To Create A New Project In Yarn
In this step, create a new project using the yarn init command and later followed by the project’s name. For example:
yarn init my_first_project
After that, you will be prompted to answer a couple of questions. You can decide to answer Yes or No or simply hit ENTER to proceed to the next question.
A package.json file is created at the end and you can confirm it.
ls -l package.json
This file contains all the info you have just provided.
To view the contents of it:
cat package.json
5- How To Install Packages Using Yarn
Install the package by typing:
yarn add [package_name]
For example,
yarn add express
Also, you can remove the package, simply by running:
yarn remove express
Conclusion
In this article, you learned How to install Yarn on CentOS 8. Please be aware that, Yarn comes with useful benefits that seek to compensate for npm’s shortcomings. It’s much faster, secure and is gradually overtaking npm as Node’s favorite package manager. With Yarn, you can deploy your projects with ease and comfort while avoiding the inconveniencies that are occasioned with npm. In a nutshell, Yarn is the better of the two. If you need to see the same guide for windows OR Ubuntu, check them on our website.
Are the NPM and yarn installations the same?
While the npm install command installs dependencies from the package. json file and allows you to add new packages, The yarn install only installs the dependencies listed in yarn.
Is yarn faster than npm?
If we compare them from point of speed, Yarn is much faster than most of npm versions.
Please guide me to add dependency
If you need to add a package as dependency to your project, run (yarn add) followed by the package name:
yarn add [package_name]
how the dependency should be updated?
You can use any of the following commands to upgrade the packages.
• yarn upgrade
• yarn upgrade [package_name]
• yarn upgrade [package_name]@[version_or_tag]
Is it possible to install yarn with script?
Yes sure. The simplest and easiest way to install Yarn from the script available at the Yarn official website with the following command:
curl -o- -L https://yarnpkg.com/install.sh | bash