How to Install Yarn on Ubuntu 24.04 (via 3 Methods)

Yarn is a popular package manager for JavaScript that is known for its speed, reliability, and security. If you are using Ubuntu 24.04 and want to install Yarn, there are several methods you can choose from. In this article, we will guide you through three different ways to install Yarn on your Ubuntu system.

Method 1: Install Yarn using APT (Advanced Package Tool)

The easiest way to install Yarn on Ubuntu 24.04 is by using the Advanced Package Tool (APT). First, you need to update the package index and install the prerequisite packages by running the following commands in your terminal:

sudo apt update
sudo apt install curl gnupg2

Next, import the Yarn GPG key and add the Yarn repository to your system by running the following commands:

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Finally, install Yarn using the APT package manager by running the following command:

sudo apt update
sudo apt install yarn

Once the installation is complete, you can verify that Yarn is installed by running the following command:

yarn --version

Method 2: Install Yarn using NPM (Node Package Manager)

If you have Node.js and NPM (Node Package Manager) installed on your Ubuntu system, you can also install Yarn using NPM. Simply run the following command in your terminal:

sudo npm install -g yarn

This command will install Yarn globally on your system, and you can verify the installation by running the following command:

yarn --version

Method 3: Install Yarn using a Bash Script

If you prefer a more manual approach, you can also install Yarn on Ubuntu 24.04 using a Bash script. First, create a new file called install-yarn.sh and open it in a text editor. Copy and paste the following script into the file:

#!/bin/bash
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install yarn

Save the file and make it executable by running the following command:

chmod +x install-yarn.sh

Finally, run the Bash script to install Yarn on your Ubuntu system:

./install-yarn.sh

After the installation is complete, you can verify that Yarn is installed by running the following command:

yarn --version

In conclusion, installing Yarn on Ubuntu 24.04 is a straightforward process, and you can choose the method that best suits your preferences. Whether you use the APT package manager, NPM, or a Bash script, you can start using Yarn to manage your JavaScript dependencies efficiently.

Tags: 117811781178