For developers, the use of dependency managers is very common. Thanks to this, they avoid having to install dependencies manually and save time. That’s why in this tutorial we will show you how to install Yarn on Ubuntu to improve your project development on Ubuntu. VPS!
Table of Contents
What is Yarn?
Yarn’s speed is due to efficient use of the cache to eliminate the need to download libraries multiple times. Meanwhile, the checksum verifies the integrity of the libraries to make sure Yarn is very secure, so very reliable.
Now, we will show how to install Yarn on Ubuntu 18.04.
How to install Yarn on Ubuntu 18.04
The most efficient way to install Yarn on Ubuntu 18.04 is through its repository. We should be able to update the app along with the rest of the system easily. The steps to install Yarn are as follows:
1. Access the server via SSH
To do this, we must access a server running Ubuntu 18.04. If you’re in trouble, check it out PuTTY tutorial ours.
2. Add GPG . Key
Run the following command:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
With the above command, we have added the necessary GPG key to ensure the downloaded packages are authentic.
3. Add Yarn . Repository
Then we can add the Yarn repository with the following command:
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
4. System Update and Install Yarn on Ubuntu
Now, all we need to do is refresh the source of the software and install Yarn on Ubuntu using APT.
sudo apt update sudo apt install yarn nodejs
5. Check the version of Yarn
Then to check if the installation was successful we can export the already installed version:
yarn init v1.15.2
And as we can see, Yarn’s installation was successful and we are ready to go.
How to use Yarn on Ubuntu
The basic usage of Yarn is pretty straightforward. First of all, we start the new project with the following command:
yarn init project_name
After that, we will be asked some questions related to the project that will later create the file .json, where the dependency we will put. If we want Yarn to use the default information for the file, we press enter for each question.
To add a dependency to the project, simply use the following command:
yarn add [package]
However, it is also possible to define a specific version of a package or library as a dependency of the project.
yarn add [package]@[version]
To update the package, we use the upgrade directive and the package name. Eg:
yarn upgrade [package]
We can also specify the version of the package to be updated:
yarn upgrade [package]@[version]
Alternatively, we can remove the package from the project with the command:
yarn upgrade [package]
Finally, to install all the defined dependencies, use the following command:
Remember that dependency is defined in file packages.json.
Otherwise, you should visit Yarn’s website and consult official document. This way you will have more information and be able to use the full potential of this popular tool. Let’s install yarn now!