How to install Yarn on Linux

By Angus Published 15 January 2025 Updated 4 March 2026 3 min read

Yarn is a JavaScript package manager for Node.js projects. It caches packages locally for faster installs, verifies packages with checksums and maintains consistent dependency trees across environments.

You will install Yarn globally on your Linux system using either npm or cURL. Once installed, you can manage Node.js packages across all your projects and control which Yarn version you use.

Before you begin

  • You need root or sudo access to your Linux system.
  • For the npm method, Node.js must be installed on your system.
  • For the cURL method, cURL must be installed on your system.

Check if Yarn is already installed

Before installing Yarn, you should check whether it already exists on your system. This prevents conflicts and shows you which version is currently active.

Run this command to check for Yarn:

yarn --version

If Yarn is installed, you will see a version number. If you see “command not found”, Yarn is not installed and you can proceed with one of the installation methods below.

Install Yarn with npm

Installing Yarn globally with npm makes it available to all Node.js projects on your system. The -g flag installs Yarn system-wide rather than in a single project directory.

  1. Install Yarn globally.
    Run the following command with sudo to install Yarn for all users:
sudo npm install -g yarn
  1. Verify the installation.
    Check that Yarn installed correctly by viewing the version number:
yarn --version

Yarn is now installed and ready to manage packages in your Node.js projects.

Install Yarn with cURL

If npm is not available on your system, you can download and install Yarn directly using cURL. This method fetches the latest Yarn installation script and runs it automatically.

  1. Download and run the Yarn installation script.
    Use cURL to fetch the script from the official Yarn repository and pipe it to bash:
curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
  1. Reload your shell configuration.
    The installation script adds Yarn to your PATH. Reload your shell to apply the changes:
source ~/.bashrc

If you use a different shell, replace ~/.bashrc with your shell’s configuration file, such as ~/.zshrc for Zsh.

  1. Verify the installation.
    Confirm Yarn is available by checking the version:
yarn --version

Yarn is now installed and configured in your shell environment.

Manage Yarn versions

After installing Yarn, you can control which version your system uses. This allows you to pin a specific version for compatibility or update to the latest release.

To set a specific Yarn version, run:

yarn set version [version_number]

Replace [version_number] with the version you need, such as 1.22.19.

To update to the latest Yarn version, run:

yarn set version latest

This fetches and installs the most recent stable release.

Wrapping up

You have installed Yarn on your Linux system and verified it works correctly. You can now use Yarn to manage Node.js packages across all your projects, with the option to control which version you run.

If you are setting up a Node.js development environment, you might also want to install MERN stack on AlmaLinux. For more control over your development environment, explore our VPS hosting options.

Need more power?

Get scalable resources with our VPS hosting with root access and optional software.

Get VPS Hosting

Starting something new?

Perfect for websites and small businesses unlimited bandwidth with cPanel hosting.

Get cPanel Hosting