Step by Step Instructions on How to Install Yarn on Ubuntu
The idea of Yarn is to accelerate the setup process for npm packages by ensuring that network connectivity errors are reduced to a minimum. We prepared a Yarn install guide for those of you who are looking to start using this package manager.
What Do You Need to Install Yarn on Ubuntu?
First of all, you will need super-user privileges, so please note that you might need to use the “sudo” prefix before the commands unless you are logged in with the root account.
Please note that you will use the official Yarm repository to install the utility. We believe that is the best option since it will ensure that you always have the latest version of the software.
How to Start a Yarn Install on Ubuntu
We will need to import the GPG key of the repository, which we can do by typing the below line into the terminal:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add --
Next, type the following command:
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
It will add the repository that Yarn officially uses and get everything ready for the installation.
Before executing the setup process, we need to perform a package list update:
It is now time to install Yarn with the following command:
apt install yarn
Please note that the Yarn installation will also install recommended add-ons you need to run the package manager properly, such as Node.js. See how to install Node.js on Ubuntu here.
If you want to confirm that the Yarn installation was completed, type the below line, and the system will display the current version of the software:
As long as everything went right, the system will immediately show the current version of Yarn on your system.
How to Start Using Yarn on Ubuntu
If you are a Yarn newbie, allow us to mention several commands that you may consider useful in the beginning.
Create a New Project
The initial thing that you want to do when using Yarn is to start a new project. You can do this by typing the command below:
yarn init project_name1
Make sure to change the name of the project to the one that you want to use.
This will only initiate the process of creating a project. You will also have to respond to a series of questions, such as specifying the project version, description, author, and others. When answering, you can type the answer or hit enter right away to use the default parameters and move on to the next question.
You will notice that a “package.json” file was created with your new project details. If you want, you can modify the information in this file easily.
Add, Update, and Remove Dependencies
Yarn allows you to use different packages in projects, but you need to ensure to add dependencies to a particular project. Here is the command you can use to do that:
yarn add name_of_the_package1
Please note that the dependencies will be added for all users working on the project.
If you need a specific tag or version of the package, use this line:
yarn add name_of_the_package1@tag_or_version
Both of the above commands can also be used for upgrading dependencies. You only need to switch “add” with the “upgrade” option.
An example would be:
yarn upgrade name_of_the_package1
If you do not need a dependency anymore, remove it with this line:
yarn remove name_of_the_package1
If you are not sure about which project dependencies to add, how about installing all of them? You can do that by running the following command:
Please note that this will install dependencies listed in the “package.json” file.
Yarn is a useful package manager for Linux users, especially those dealing with npm packages. The process of installation via the command line is straightforward, and you can also manage dependencies effortlessly.
If you are a fan of using Python programming language, you can make your life easier by using Python Pip. It is a package management utility that allows you to install and manage Python software packages easily. Ubuntu doesn’t come with pre-installed Pip, but here…
If you are looking for a convenient way to manage Java applications on Ubuntu, the solution may lie in the IntelliJ IDEA development platform. An excellent advantage of this option is that it is relatively suitable for beginners, but experienced users will also find it…