An exercise in futility

Installing Yarn

23 Mar 2024

How to Install Yarn: A Step-by-Step Guide

Yarn is a fast, reliable, and secure dependency management tool that has become a popular choice among developers, particularly those working with JavaScript projects. It caches every package it downloads, so it never needs to download the same package again. It also parallelizes operations to maximize resource utilization, so install times are faster than ever. This guide will walk you through the process of installing Yarn on your system, ensuring you can start managing your project dependencies more efficiently.

Prerequisites

Before installing Yarn, you need to have Node.js installed on your system. Yarn requires Node.js to run, as it is built on top of the Node.js runtime. You can check if Node.js is installed by running the following command in your terminal:

node -v

If Node.js is not installed, you should download and install it from the official Node.js website.

Installing Yarn

Yarn can be installed in several ways, depending on your operating system and preferences. Below are the methods for installing Yarn on various platforms.

Windows

For Windows users, Yarn can be installed via the Windows Installer or through the package manager Chocolatey.

Using Windows Installer

  1. Download the Yarn installer from the official Yarn website.
  2. Run the installer and follow the installation instructions.
  3. Once installed, open a command prompt and run yarn --version to verify the installation.

Using Chocolatey

If you prefer to use Chocolatey, a package manager for Windows, you can install Yarn by running:

choco install yarn

macOS

macOS users can install Yarn through the Homebrew package manager.

Using Homebrew

  1. Open the Terminal.
  2. If Homebrew is not already installed, install it by running:

     /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
  3. Install Yarn by running:
brew install yarn

Linux

On Linux, Yarn can be installed through the native package managers of various distributions, or via npm, the Node.js package manager.

Using npm

You can install Yarn globally using npm by running:

npm install -g yarn

Using Debian or Ubuntu Package Manager

For Debian or Ubuntu-based distributions, you can run:

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
sudo apt-get update && sudo apt-get install yarn

Using Fedora or CentOS

For Fedora or CentOS, use the following commands:

sudo dnf config-manager --add-repo https://dl.yarnpkg.com/rpm/yarn.repo
sudo dnf install yarn

Verifying the Installation

After installation, you can verify that Yarn is installed correctly by opening a terminal or command prompt and running:

yarn --version

This command should return the version of Yarn installed on your system, indicating that Yarn has been successfully installed.

Conclusion

With Yarn installed, youโ€™re now ready to manage your project dependencies more efficiently. Yarnโ€™s speed and reliability can significantly improve your development workflow, especially in projects with a large number of dependencies. Remember to consult the Yarn documentation for more advanced features and usage instructions, enhancing your development experience even further.