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?
- 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
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:
Also, you can check the npm version by entering the following command:
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:
In this step, go to your existing project directory with the help of the following command:
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:
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:
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:
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:
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
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.