UbuntuUbuntu Based

How To Install Yarn on Ubuntu 24.04 LTS

Install Yarn on Ubuntu 24.04

In the world of JavaScript development, Yarn has emerged as a popular package manager that offers speed, reliability, and security. It provides an efficient way to manage project dependencies, ensuring a consistent and reproducible development environment. As Ubuntu 24.04 continues to be a widely used Linux distribution, it’s crucial for developers to know how to install Yarn on this operating system.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Yarn on Ubuntu 24.04 (Noble Numbat). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.

Prerequisites

  • A server running one of the following operating systems: Ubuntu and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
  • An Ubuntu 24.04 system with root access or a user with sudo privileges.

Install Yarn on Ubuntu 24.04 LTS

Step 1. Updating the Package Repository.

Before installing BleachBit, it’s essential to update your system packages to ensure compatibility and avoid potential issues. Open a terminal and run the following command:

sudo apt update
sudo apt upgrade

This command will refresh the package lists and upgrade any outdated packages to their latest versions. Keeping your system up-to-date is a good practice for maintaining stability and security.

Step 2. Installing Node.js.

Before diving into the installation process, it’s essential to ensure that your system has Node.js installed. Yarn relies on Node.js to function properly. To check if Node.js is already installed on your Ubuntu 24.04 system, open a terminal and run the following command:

node -v

If Node.js is installed, the command will display the version number. If you don’t have Node.js installed or need to update to a newer version, you can use the following commands:

sudo apt update
sudo apt install nodejs

Once Node.js is set up, you’re ready to proceed with installing Yarn.

Step 3. Installing Yarn on Ubuntu 24.04.

  • Method 1: Install Yarn Using Corepack

Corepack is a new feature introduced in Node.js 16.10 and later versions that simplifies the management of package managers like Yarn. It allows you to easily enable and use different versions of Yarn without the need for global installation. Here’s how to install Yarn using Corepack:

corepack enable

If Corepack is not available on your system, you can install it globally using npm:

sudo npm install -g corepack

Once Corepack is enabled, you can install Yarn by running:

corepack prepare yarn@stable --activate

To verify the installation, run:

yarn --version

If the installation was successful, you should see the Yarn version number displayed in the terminal.

  • Method 2: Install Yarn via NPM

If you prefer using npm (Node Package Manager) to install Yarn, follow these steps:

sudo apt install npm

Once npm is installed, you can install Yarn globally by running:

sudo npm install -g yarn

After the installation is complete, verify the installation by running:

yarn --version

If the installation was successful, you should see the Yarn version number displayed in the terminal.

  • Method 3: Install Yarn via APT Repository

Another way to install Yarn on Ubuntu 24.04 is by using the APT package manager. This method involves adding the official Yarn repository to your system and installing Yarn from there. Here’s how to do it:

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

Add the Yarn repository to your system’s package sources by running:

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

Update the package list and install Yarn by running:

sudo apt update && sudo apt install yarn

After the installation is complete, verify the installation by running:

yarn --version

If the installation was successful, you should see the Yarn version number displayed in the terminal.

If you ever need to uninstall Yarn installed via the APT repository, you can use the following commands:

sudo apt remove --autoremove yarn
sudo rm /etc/apt/sources.list.d/yarn.list

Step 4. Basic Yarn Operations.

Now that you have Yarn installed on your Ubuntu 24.04 system, let’s explore some basic operations you can perform with Yarn.

  • Initialize a new Yarn project:
yarn init
  • Add dependencies to your project:
yarn add <package_name>
  • Remove dependencies from your project:
yarn remove <package_name>
  • Install all project dependencies:
yarn install
  • Upgrade packages to their latest versions:
yarn upgrade
  • Audit your project for vulnerabilities:
yarn audit
  • Clean the Yarn cache:
yarn cache clean

Congratulations! You have successfully installed Yarn. Thanks for using this tutorial for installing the Yarn on the Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Yarn website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button