How to Install Yarn on Ubuntu 24.04

Install Yarn on Ubuntu 24.04

Yarn is a package manager for JavaScript. It is used to manage dependencies in JavaScript projects. People prefer it over NPM, because of its speed and reliability. Yarn is more secure than NPM in terms of installation and usage. Moreover, it allows the users to share and use the JavaScript code with other developers from around the world. Yarn does not come preinstalled on Ubuntu, however, it can be installed manually with a certain set of instructions. This article will cover a comprehensive guide to install Yarn on Ubuntu 24.04.

How to Install Yarn on Ubuntu 24.04

The installation of Yarn on Ubuntu requires some of the prerequisites, such as installation of Node.js and cURL. We have covered each step in simple detail below to help you understand the installation of yarn on Ubuntu.

Step 1: First, update system repositories by executing the given command in the Terminal:

sudo apt update

sudo apt update
Step 2: Node.js installation is necessary for Yarn to function properly on Ubuntu. If you don’t have Node.js is not installed on Ubuntu, then, execute the below command to install it:

sudo apt install nodejs

sudo apt install nodejs
Step 3: You have to add Yarn to the Ubuntu repository because it is not automatically available there.

To add a Yarn repository you must have cURL installed on your system. To install cURL on Ubuntu, execute this command:

sudo snap install curl

sudo snap install curl
Step 4: Once the cURL is installed, execute this command to add Yarn repository to the Ubuntu system:

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

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
Step 5: Afterward, add Yarn repository to the sources list by running the listed command:

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

echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
Step 6: Update the system repositories so all the changes can take effect:

sudo apt update

sudo apt update
Step 7: Lastly, install Yarn by executing the given command:

sudo apt install yarn

sudo apt install yarn
Step 8: Once the Yarn is installed, verify its installation by checking its version with the help of the following command:

yarn --version

yarn --version

Conclusion

To install Yarn on Ubuntu 24.04, firstly, install Node.js which is needed for proper working of Yarn. To install Node.js on Ubuntu, run this command sudo apt install nodejs. Then, run this command curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add – to add Yarn to Ubuntu repositories using cURL tool. Then, add the Yarn repository to the sources list by executing this command echo “deb https://dl.yarnpkg.com/debian/ stable main” | sudo tee /etc/apt/sources.list.d/yarn.list. With the completion of all the steps, finally, run this command sudo apt install yarn to install Yarn on Ubuntu 24.04.

If you loved this tutorial, subscribe to Linux World for more how-tos and articles.