In this post, we'll show you how to install Yarn on Ubuntu 22.04 LTS (Jammy Jellyfish).
Step 1: Update Your System
Before we begin, let's make sure that our system is up to date. Open a terminal window and run the following command:
sudo apt update && sudo apt upgrade
This command will update the package list and upgrade any outdated packages on your system.
Step 2: Install Node.js
Yarn is built on top of Node.js, so you'll need to install it before you can install Yarn. Run the following command to install Node.js:
sudo apt install nodejs
Step 3: Install Yarn
Now that we have Node.js installed, we can install Yarn. There are two ways to install Yarn on Ubuntu 22.04: using the official Yarn repository, or using npm.
Option 1: Installing Yarn from the Official Repository
To install Yarn from the official repository, run 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
Then simply run this command:
sudo apt update && sudo apt install yarn
nvm you can avoid the
node installation by doing:
sudo apt update && sudo apt install --no-install-recommends yarn
Note: Ubuntu versions may come with
cmdtest installed by default. If you’re getting errors from installing
yarn, you may want to run first before installing Yarn:
sudo apt remove cmdtest
Option 2: Installing Yarn using npm
If you prefer to install Yarn using npm, you can run the following command:
sudo npm install -g yarn
This will install Yarn globally on your system.
Step 4: Path Setup (Optional)
If Yarn is not found in your PATH, follow these steps to add it and allow it to be run from anywhere.
Note: your profile may be in your
- Add this to your profile:
export PATH="$PATH:/opt/yarn-[version]/bin"(the path may vary depending on where you extracted Yarn to)
- In the terminal, log in and log out for the changes to take effect
To have access to Yarn’s executables globally, you will need to set up the
PATH environment variable in your terminal. To do this, add
export PATH="$PATH:`yarn global bin`" to your profile, or if you use Fish shell, simply run the command
set -U fish_user_paths (yarn global bin) $fish_user_paths
Step 5: Verify the Installation
Once the installation is complete, you can verify that Yarn is installed by running the following command:
If Yarn is installed correctly, you should see the version number printed in the terminal.
In this guide, we showed you how to install Yarn on Ubuntu 22.04. Yarn is a powerful tool that can help manage your Node.js dependencies and streamline your Node.js development workflow. If you're interested in learning more about Yarn, check out the official Yarn website or our guide to getting started with Yarn.