How to Install Yarn on Ubuntu?( 3 Methods )

There are numerous package managers available for coders and programmers. NPM is one of them, but it’s very bloated. I use NPM but am always on the lookout for the others. The Yarn is one promising package manager that was developed by Meta { Previously known as Facebook ). This is developed for the Node.js Runtime environment with the intention of replacing NPM.

Yarn is considered superior to NPM as it provides numerous features. With the Caching of downloads, the users don’t have to restart the failed downloads. Also, it provides faster performance, effective dependency tracking and also parallel installations.

Installing it on Windows is easier, but there is not much documentation available for the installation on Linux. I’ve tried various ways to install Yarn on Ubuntu and helping you with the same. In this post, I am going to share the multiple ways to install Yarn on your Ubuntu or related distributions.

Install Yarn on Ubuntu

How to Install Yarn on Ubuntu and Other Distributions?

Yarn can be installed on your Ubuntu system with APT Package manager, Node Package Manager or NPM and Corepack method. You have to choose the one method that is most convenient for installation.

Method #1 – Use NPM to Install Yarn

You can easily install it through the NPM, as it works with the Node.js Runtime environment. If you don’t have NPM, then you have to install it before proceeding with Yarn Installation.

  • Open the Terminal and then paste or type the following command. This will install the NPM on your system. You can skip it if you have installed it already.
sudo apt install npm
  • Once NPM installation finishes, check the version number to confirm the installation.
npm --version
  • You will see the currently installed version number of NPM. After that, it’s time to install the Yarn package through NPM. Paste the following command to start the installation.
sudo npm install -g yarn
  • The installation will take a few seconds or even minutes to finish. Once finished, type the following command to check the version of installed Yarn modules.
yarn --version
  • You will see the version number output and you are ready to use it as you need. If you don’t want to follow this method, then you should check out the other methods for convenience.

Method #2 – Installing Yarn with Corepack

With Corepack, you don’t have to install the Yarn directly, as it’s included in the package.This tool allows you to use the third-party JavaScript package managers for Node environment with ease. Here are the exact steps for you to install Corepack and enable Yarn on Ubuntu.

  • Just like any other method, you need to open Terminal Window. You can do it with ” Ctrl + Alt + T” key combination.
  • Now, paste the following command to start installing Corepack through NPM.
sudo npm install -g corepack
  • The Corepack modules will be installed. Now, you only have to enable the Yarn on Ubuntu 24.04. Enter the following command.
corepack enable
  • This will enable the Corepack and now you can enable any of the available Package managers. We are going to enable Yarn on Ubuntu 22.04 and higher versions.
corepack prepare yarn@stable --activate
  • This will enable the Yarn. You have to check the status by typing the following command. It will show the version details.
yarn --version

That’s it! Corepack tool reduces the overall work of installing multiple package managers.

Method #3 – Install Via APT Repository

APT is the most common way to install any packages on Ubuntu and related distributions. There is no official version in the Universal repository, so you must add the YARN 4.4 repository.

Open the Terminal window from Applications Menu or “Ctrl + Alt + T” key combination. Type or paste the following command and press ENTER.

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

Now, add the Yarn repository details into the System sources file. This command prints the Yarn repository details after successful completion.

echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

After that, update the database and then install it on your system with following command.

sudo apt update && sudo apt install yarn

Depending on the internet speed, the installation will complete within a few seconds. After that, check the version details of the YPM.

yarn --version

That’s it. You will now have access to Yarn and use it as you want to build projects.

How to Uninstall Yarn from Ubuntu Linux?

If you want to uninstall it for one reason or another, you should follow these steps. As I’ve shared three methods to install it, there are three ways to uninstall it. Just open the Terminal and type the appropriate command to uninstall.

For NPM Installation

sudo npm remove -g yarn

For Corepack Installation

corepack disable

sudo npm uninstall -g corepack

For APT Installation

sudo apt remove --autoremove yarn

sudo rm /etc/apt/sources.list.d/yarn.list

Conclusion

The YPM for Node.js environment is perfect for people who want to have a better experience. With this package manager, you can perform parallel downloads with yarn.lock method, which is not possible with NPM. I am not much of a developer, so I just tried my best to talk about the ways to install this package manager. If you want some assistance or have some doubts, you are free to ask for help in the comments section.

Posted In :

Leave a Reply

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

Swaraj Nandedkar