How to Install Yarn on Windows

Yarn is a popular package manager for JavaScript projects developed by Facebook. It offers several advantages over npm such as faster dependency installation better security and more reliable package management. While it is primarily associated with Node.js development Yarn can be used for various JavaScript based applications.

In this post, we will cover the process of installing Yarn on Windows operating system using different methods and configurations along with troubleshooting steps.

Installation Methods

Following are four methods described below while installing yarn on Windows operating system:

Method 1: Install Yarn via NPM

The most common way to install Yarn is through npm which comes bundled with Node.js. If you have not already installed Node.js refer to our guide on how to install Node.js and NPM on Windows operating system.

After installing, open the start menu and type “Command Prompt”. To verify that npm is installed correctly, run the following command:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
npm -v
npm -v
npm -v

If npm is installed you will see its version number.

npm version

After that, run the following command to install Yarn globally:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
npm install -g yarn
npm install -g yarn
npm install -g yarn

This will download and install Yarn to your system’s global directory.

npm yarn

After the installation is complete verify it by running the following command:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
yarn --version
yarn --version
yarn --version

This command should display the version of Yarn installed on your system.

yarn version

Method 2: Install Yarn via MSI Installer

Another method to install Yarn is by using the MSI installer. This method is simple and user-friendly.

Go to the official Yarn website and download the MSI installer.

yarn website

Double click the downloaded .msi file in your “Download” folder to launch the installer.

yarn msi

The installation setup wizard will appear, Click “Next” to continue.

yarn setup


Accept the End user License agreement, Click “Next” to continue.

License Agreement


Set the directory path which is usually “Program Files (x86)” for installation.

Destination Folder


After that, the installation started immediately. When the installation is complete verify by running the version command.

Method 3: Install Yarn via Chocolatey

Chocolatey is a package manager for Windows that simplifies the installation of software. If you have Chocolatey installed on Windows you can use it to install Yarn.

Open PowerShell as Administrator by pressing Win + X and select “Windows PowerShell (Admin)”. Run the following command to install Yarn:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
choco install yarn
choco install yarn
choco install yarn
yarn choco

After the installation is complete verify it by running the version command.

Method 4: Install Yarn via Scoop

Scoop is another package manager for Windows that can be used to install Yarn. Note that Scoop does not automatically install Node.js so you need to have Node.js installed beforehand.

Open PowerShell as Administrator by pressing Win + X and select “Windows PowerShell (Admin)”. If you have not installed Scoop run the following command:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
iwr -useb get.scoop.sh | iex
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser iwr -useb get.scoop.sh | iex
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
iwr -useb get.scoop.sh | iex

Run the following command to install Yarn:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
scoop install yarn
scoop install yarn
scoop install yarn

Configuring Yarn

After Yarn Windows installs you might want to configure it to suit your development environment. Here are some common configurations:

Set Yarn Registry

You can set the Yarn registry to a custom URL if needed:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
yarn config set registry <registry_url>
yarn config set registry <registry_url>
yarn config set registry <registry_url>

Enable Offline Mode

Yarn supports offline mode which allows you to install packages without an internet connection:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
yarn config set yarn-offline-mirror <path_to_mirror>
yarn config set yarn-offline-mirror <path_to_mirror>
yarn config set yarn-offline-mirror <path_to_mirror>

Global Packages

You can install packages globally using Yarn:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
yarn global add <package_name>
yarn global add <package_name>
yarn global add <package_name>

Using Yarn

Once Yarn is installed you can start using it to manage your JavaScript projects. Here are some basic commands:

1. Initialize a New Project: To create a new project navigate to your project directory and run:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
yarn init
yarn init
yarn init

2. Add Dependencies: To add a new dependency to your project, run:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
yarn add <package_name>
yarn add <package_name>
yarn add <package_name>

3. Remove Dependencies: To remove a dependency, run:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
yarn remove <package_name>
yarn remove <package_name>
yarn remove <package_name>

4. Install All Dependencies: To install all dependencies listed in your package.json file, run:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
yarn install
yarn install
yarn install

5. Upgrade Dependencies: To upgrade a dependency to the latest version, run:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
yarn upgrade <package_name>
yarn upgrade <package_name>
yarn upgrade <package_name>

Troubleshooting Steps

If you encounter issues while installing or using Yarn, here are some common troubleshooting steps:

  • Ensure you have installed the latest versions of Node.js and npm.
  • Sometimes clearing the Yarn cache can resolve issues.
  • If all else fails try uninstalling and reinstalling Yarn.

Conclusion

Installing Yarn on Windows is a straightforward process and you have multiple methods to choose from. Whether you prefer using npm the MSI installer Chocolatey or Scoop, you can easily set up Yarn and start managing your JavaScript projects efficiently. With its speed reliability and security features, Yarn is a valuable tool for any developer working with JavaScript.

While installing Yarn on Windows is straightforward managing dependencies and ensuring compatibility across different server environments can be technical. Upgrading to Ultahost’s Windows VPS hosting plan empowers you with a robust solution that helps you to install the latest package managers and repositories simplifying Yarn installation and updates.

FAQ

What is Yarn?

Related Post

How to Install ReactJS on Windows

ReactJS is a JavaScript library for building dynamic us...

How to Install Concrete on Windows

Concrete CMS, formerly known as concrete5, is a powerfu...

How to Install TYPO3 on Windows 10

TYPO3 is a powerful, open-source content management sys...

How to Install October CMS on Windows

October CMS is a popular free and open-source CMS built...

How to Install Curl on Windows?

Curl stands for Client URL is a popular command-line to...

How to Install Drupal on Windows

Drupal is a powerful tool for creating and managing onl...

Leave a Comment