In the next article we are going to take a look at Yarn. This is a kind of JavaScript package installer and dependency manager released by Facebook in collaboration with other developers like Google. This installer introduces changes in dependency management, task execution, and some performance improvements.
Yarn supports NPM registration, but differs in package installation. It uses lock files and a deterministic installation algorithm, allowing you to keep the same directory structure node_modules for all users involved in a project. This can help reduce errors that are difficult to track across multiple machines.
In most programming projects, dependency management is an important task. Yarn is a fast, secure and reliable package dependency manager for NodeJS applications. This is compatible with NPM, used to install, configure, update and remove packages.
Yarn is an open source manager, which creates a cache for the downloaded package on the user's machine and can reuse this package when needed, without downloading it over and over again. Using checksums, this package manager verifies the integrity of each installed package before executing its code. Additionally Yarn can be used in offline mode.
In the following lines we will see how to install Yarn on Ubuntu 20.04 LTS using command line environment. To use it we need NodeJS , because it depends on him.
Table of Contents
Install Yarn on Ubuntu 20.04 LTS
An official repository on Ubuntu 20.04 LTS is available for installation. Using this PPA, we can install Yarn globally on the system. To proceed with the installation on our computer, we will have to open a terminal (Ctrl + Alt + T) and then follow each of the following steps:
Install cURL on Ubuntu 20.04 LTS
If you don't have this tool installed on your system yet, you can install it from the official Ubuntu 20.04 LTS package repository. All you have to do is run the following command to install cURL:
sudo apt install curl
Add GPG key
Once we have correctly installed cURL in the system, before starting with the installation, we are going to add GPG key to verify Yarn packets. To import the GPG key, you just have to type the following command in the same terminal (Ctrl + Alt + T):
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
Enable the Yarn repository
To begin the installation, first we are going to add and enable the necessary repository in Ubuntu 20.04 LTS. To do so, in the same terminal we are going to use the command:
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
Update the cache and install Yarn
At this stage, first we will update APT cache and then Yarn will be installed on Ubuntu 20.04 LTS using the following command:
sudo apt update && sudo apt install yarn
If you are currently using Nodejs and NPM, then you can install Yarn by typing the following command in the terminal (Ctrl + Alt + T):
sudo apt install --no-install-recommends yarn
Check Yarn Version
Once the installation is complete, we will be able to check whether it installed successfully on our Ubuntu 20.04 system or not. We will do this by executing in our terminal (Ctrl + Alt + T):
yarn --version
After executing the above command, the terminal will show us the installed version.
Install packages with Yarn
Most packages will be installed from the NPM registry and will be named simply by their package name. For example, if we wanted to install the package react of the NPM registry we would not have more to write the command:
yarn add react
For more information about how to install packages with Yarn, users can consult the documentation in this regard that we can find in the project website.
If you need more information on installing Yarn on Ubuntu, users can consult the project page. On this page we can also find the Documentation about the project. We will also find your code and more information from the Yarn page at GitHub.
Be the first to comment