Advance

How to Install Yarn on Ubuntu 22.04

How to Install Yarn on Ubuntu 22.04

Package Manager is a tool that installs, updates and manages the software packages you need. with the help of such tools, you can always have the latest version of the libraries you need with your software, and without having to search and check their packages and peripherals, you can only think about developing the core of your software. Yarn also is a package manager and In this article, we are going to teach you how to install Yarn on Ubuntu 22.04. Also, you can visit the packages available in Eldernode if you wish to purchase a Linux VPS Hosting.

What is Yarn?

Yarn stands for Yet Another Resource Negotiator and is a package manager for Node.js in JavaScript that replaces NPM. The Yarn has been developed by the company and the developer to improve and fix the problems that exist in NPM. The Yarn has been developed by Facebook, Google, Exponent, and Tilde. Yarn lets users use their code and share it with other developers around the world. Also, it allows you to use other developers’ solutions to a variety of problems and makes software development easier for you.

Yarn Features

  • Install packages from the local cache of your system without the need for Internet
  • Install packages in parallel
  • Bind the package version firmly
  • High speed in installing packages
  • Simple and readable commands in CLI
  • Provide more capabilities in the field of package management
  • Has different plugins

Yarn on Ubuntu 22.04

Install Yarn on Ubuntu 22.04

Before installing Yarn, you need to install npm (Node Package Manager) on your Ubuntu 22.04 system. npm comes with Node.js.

You can install Node.js with the help of the NodeSource repository. First of all open terminal and set up the NodeSource repository for the desired Node.js version.

To set up NodeSource repository 16.x (LTS):

wget -qO- https://deb.nodesource.com/setup_16.x | sudo -E bash

To set up NodeSource repository 18.x (Current Version):

wget -qO- https://deb.nodesource.com/setup_18.x | sudo -E bash

Now install Node.js and npm by running the following command:

sudo apt install -y nodejs

You can check the Node.js version with the following command:

node --version

Also, you can check the npm version by entering the following command:

npm --version

Now it’s time to install Yarn. To do this, run the following command:

sudo npm install --global yarn

Then enter a password.

You can check the Yarn version with the following command:

yarn --version

In this step, go to your existing project directory with the help of the following command:

cd your_project

Now you need to install the latest Yarn binary for your project by entering the following command:

yarn set version berry

Then again check the Yarn version with the following command:

yarn --version

The received output indicates that your project has the latest version of Yarn.

How to Use Yarn on Ubuntu 22.04

The following command can guide you with the existing command:

yarn help

You can create a directory with the help of the following command:

mkdir my_project && cd my_project

To create a new project, just run the following command:

yarn init

After entering the above command, you will be asked a series of questions related to your project, which you can use the default values by pressing Enter. The above command also puts package.json, which contains the project information that you provided, and yarn.lock, which contains all the information about the project dependencies.

To add a dependency to your project, you can run the following command:

yarn add (package-name)
yarn add (package-name)@(version)
yarn add (package-name)@(tag)

The above command downloads and installs dependency packages and updates dependency details in package.json and yarn.lock.

You can use the following command to install all the dependencies of your projects:

yarn
yarn install

To upgrade the dependency of your project, enter the following command with the package name:

yarn upgrade (package-name)    yarn upgrade (package-name)@(version)
yarn upgrade (package-name)@(tag)

To remove the dependency that is no longer needed in the project, run the following command:

yarn remove (package-name)

You can use the following command to update Yarn:

yarn set version latest

Conclusion

This article taught you how to install and use Yarn on Ubuntu 22.04. By installing Yarn, you can install packages, start a new project, and share packages securely and reliably. I hope this article was useful for you and you can install Yarn easily on your Ubuntu system.

View More Posts
Tom Veitch
Eldernode Writer
We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day