Install Yarn on Linux & macOS in Minutes

January 24, 2023 / How-to Guide

Yarn (Yet Another Resource Negotiator) is a popular JavaScript package manager that helps improve dependency management and performance for large codebases. It is commonly used on VPS and development servers.

This guide explains how to install Yarn on supported Linux distributions and macOS.

Note: CentOS Linux (7/8) has reached End of Life (EOL) and is no longer supported.
Use CentOS Stream, AlmaLinux, or Rocky Linux instead.

Install Yarn Using npm (Linux & macOS – Recommended)
This method works reliably on both Linux and macOS.

  1. Connect to your server via SSH or open the Terminal.
  2. Run the following command:
    sudo npm install -g yarn
  3. Restart the terminal to enable Yarn commands.
  4. Verify the installation:
    yarn --version

Install Yarn on Debian / Ubuntu Using Official Repository

  1. Connect to the server via SSH.
  2. Add the Yarn GPG key:
    curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
  3. Add the Yarn APT repository:
    echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
  4. Update the package list:
    sudo apt update
  5. Install Yarn:
    sudo apt install yarn
  6. Verify the installation:
    yarn --version

Install Yarn on RPM-Based Linux (CentOS Stream, AlmaLinux, Rocky Linux)

  1. Connect to the server via SSH.
  2. Add the Yarn repository:
    curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
  3. Import the GPG key:
    sudo rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg
  4. Install Yarn:
    sudo dnf install yarn
  5. Verify the installation:
    yarn --version
Building modern applications with Yarn and JavaScript frameworks?
A Linux VPS Hosting solution provides dedicated resources and full control for efficient application deployment and management.

You have successfully installed Yarn on your Linux system or macOS. You can now manage JavaScript dependencies efficiently using Yarn commands.

For more helpful guides, visit our Knowledge Base regularly.

Also Read:  How to Upgrade Yarn on Linux

Spread the love