How to Install Yarn on Ubuntu 24.04

Yarn is a popular package manager for JavaScript that greatly simplifies the process of managing dependencies for your projects. If you are using Ubuntu 24.04 and want to install Yarn, follow the steps below to get it up and running on your system.

  1. Update your package index
    Before installing any new software, it is always a good idea to update your package index to ensure that you are installing the latest version available. You can do this by running the following command in your terminal:
sudo apt update
  1. Install Yarn using the official repository
    Yarn provides an official repository for Ubuntu users, which makes it easy to install the package manager on your system. To add the Yarn repository to your list of software sources, run the following command:
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -

Next, add the repository to your sources list:

echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
  1. Install Yarn
    Now that you have added the Yarn repository to your system, you can install the package manager by running the following command:
sudo apt update
sudo apt install yarn
  1. Verify the installation
    Once the installation process is complete, you can verify that Yarn has been installed successfully by running the following command:
yarn --version

If everything has been set up correctly, you should see the version number of Yarn printed in your terminal.

  1. Additional setup
    Finally, you may want to customize your Yarn configuration by creating a .yarnrc file in your home directory. This file allows you to specify default values for various Yarn options, such as the registry to use and the location of the cache directory.

To create a .yarnrc file, run the following command:

echo "--registry=https://registry.yarnpkg.com" > ~/.yarnrc

You can edit this file to add any other configuration options that you may need.

By following these steps, you should now have Yarn installed and ready to use on your Ubuntu 24.04 system. Happy coding!

Tags: 171171