25th Anniversary Savings | 25% Off Dedicated Servers*Shop Now
25th Anniversary Savings | 25% Off VPS Hosting* †††Shop Now
Limited Inventory: High-Performance AMD-Powered Servers Now Available.* Shop Now >

4 Methods for How to Install Yarn on Windows Server

Reading Time: 8 minutes

What Is Yarn?

Yarn is a package manager that helps develop JavaScript code and share it through software packages. A team at Facebook developed it as an alternative to the Node package manager (NPM) client and focused on speed, security, and consistency. Packages, also known as modules, are used to distribute the code. A package.json file outlines the contents of the package and all associated, distributed code.

There are multiple ways to install the Yarn on a Windows server. This tutorial offers four methods for how to install Yarn on Windows Server.

Prerequisites to Installing Yarn on Windows Server

  • A host with Windows Server installed.
  • Node.js is installed on the server.
  • Windows PowerShell running on the server.
  • Administrator access to the server.

4 Methods for How to Install Yarn on Windows Server

Here are 4 Methods to install Yarn on a windows server.

Install Yarn on Windows Server via the MSI Installer

Step 1:

First, you need to download the Yarn install package. Download the Yarn .msi installer from the official Yarn website.

Step 2: 

Locate and double-click on the downloaded package. A message box will appear, where you will click Run.

Step 3:

A new welcome wizard will pop up for the Yarn install setup. Click Next.

Step 4:

The next screen displays the license agreement details. Click the checkbox near the bottom of the window to accept the license agreement, and click Next.

Step 5:

To complete the Yarn package installation, click Install.

Step 6:

Once the Yarn install is completed, a confirmation message box will appear. Click Finish.

Step 7:

Now, run the following Yarn version check command on the Windows PowerShell to verify the completion of the Yarn package install.

yarn --version

The output will show the version number, signifying that it is installed.

PS C:\Users\Administrator> yarn --version
1.22.18
PS C:\Users\Administrator>

How to Install the Yarn Package Using Chocolatey

Chocolatey is a command line package manager and installer for Windows. The Chocolatey package manager automatically installs all dependencies for the Yarn package on the server. It also checks for a Node.js install, and if it isn't present, it will install it immediately.

Step 1:

To start the installation, open the Windows PowerShell as Administrator.

Step 2:

Run the following command to verify the execution status.

Get-ExecutionPolicy

The output should be similar to the following.

Windows PowerShell
Copyright (C) 2014 Microsoft Corporation. All rights reserved.

PS C:\Users\Administrator> Get-ExecutionPolicy
Unrestricted
PS C:\Users\Administrator>

In this example, the Get-ExecutionPolicy is Unrestricted,which is the expected output. In some cases, the output will be Restricted, and you will need to execute the following command to change it and complete the installation.

Set-ExecutionPolicy AllSigned

Type Y at the prompt to enable the Unrestricted option.

Step 3:

Run the below command on the PowerShell to complete the installation.

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

Here is the output.

PS C:\Users\Administrator>
PS C:\Users\Administrator> Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
Forcing web requests to allow TLS v1.2 (Required for requests to Chocolatey.org)
Getting latest version of the Chocolatey package for download.
Not using proxy.
Getting Chocolatey from https://community.chocolatey.org/api/v2/package/chocolatey/1.1.0.
Downloading https://community.chocolatey.org/api/v2/package/chocolatey/1.1.0 to C:\Users\ADMINI~1\AppData\Local\Temp\2\chocolatey\chocoInstall\chocolatey.zip
Not using proxy.
Extracting C:\Users\ADMINI~1\AppData\Local\Temp\2\chocolatey\chocoInstall\chocolatey.zip to C:\Users\ADMINI~1\AppData\Local\Temp\2\chocolatey\chocoInstall
Installing Chocolatey on the local machine
Creating ChocolateyInstall as an environment variable (targeting 'Machine')
  Setting ChocolateyInstall to 'C:\ProgramData\chocolatey'
WARNING: It's very likely you will need to close and reopen your shell
  before you can use choco.
Restricting write permissions to Administrators
We are setting up the Chocolatey package repository.
The packages themselves go to 'C:\ProgramData\chocolatey\lib'
  (i.e. C:\ProgramData\chocolatey\lib\yourPackageName).
A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin'
  and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'.

Creating Chocolatey folders if they do not already exist.

WARNING: You can safely ignore errors related to missing log files when
  upgrading from a version of Chocolatey less than 0.9.9.
  'Batch file could not be found' is also safe to ignore.
  'The system cannot find the file specified' - also safe.
chocolatey.nupkg file not installed in lib.
 Attempting to locate it from bootstrapper.
PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding...
WARNING: Not setting tab completion: Profile file does not exist at
'C:\Users\Administrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'.
Chocolatey (choco.exe) is now ready.
You can call choco from anywhere, command line or powershell by typing choco.
Run choco /? for a list of functions.
You may need to shut down and restart powershell and/or consoles
 first prior to using choco.
Ensuring Chocolatey commands are on the path
Ensuring chocolatey.nupkg is in the lib folder
PS C:\Users\Administrator>

Step 4:

Once the Chocolatey installation completes, install the Yarn package on the Windows server by running the following command.

choco install yarn

Here is the output. You need to type Y to run the script and complete the Yarn installation.

PS C:\Users\Administrator> choco install yarn
Chocolatey v1.1.0
Installing the following packages:
yarn
By installing, you accept licenses for the packages.
Progress: Downloading yarn 1.22.15... 100%

yarn v1.22.15 [Approved]
yarn package files install completed. Performing other installation steps.
The package yarn wants to run 'chocolateyinstall.ps1'.
Note: If you don't run this script, the installation will fail.
Note: To confirm automatically next time, use '-y' or consider:
choco feature enable -n allowGlobalConfirmation
Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): Y

Here is the output along with confirmation that Yarn has been installed.

Do you want to run the script?([Y]es/[A]ll - yes to all/[N]o/[P]rint): Y

Downloading yarn
  from 'https://yarnpkg.com/downloads/1.22.15/yarn-1.22.15.msi'
Progress: 100% - Completed download of C:\Users\Administrator\AppData\Local\Temp\chocolatey\yarn\1.22.15\yarn-1.22.15.msi (1.6 MB).
Download of yarn-1.22.15.msi (1.6 MB) completed.
Hashes match.
Installing yarn...
yarn has been installed.

Step 5:

To confirm Yarn installed correctly, check the version in the Windows Command Prompt (CMD). A quick way to access it is by the Run menu. Press the Windows + R keys and type CMD at the prompt.

Run the following command to check the Yarn version.

yarn -version

The output should contain a Yarn version.

Microsoft Windows [Version 10.0.17763.2686]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Users\Administrator>yarn --version
1.22.15

C:\Users\Administrator>

Installing the Yarn Package Using Scoop

Scoop is another command line package manager and installer for Windows. These steps guide you through the installation for both Scoop and Yarn.

Step 1:

Open the PowerShell as Administrator, then run the following command. It will set the execution policy to allow PowerShell to run local scripts.

set-executionpolicy remotesigned -scope currentuser

Here is the output.

PS C:\Users\Administrator> set-executionpolicy remotesigned -scope currentuser

Execution Policy Change
The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose
you to the security risks described in the about_Execution_Policies help topic at
https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y
PS C:\Users\Administrator>
PS C:\Users\Administrator>

Step 2:

Install Scoop using the below commands.

iwr -useb get.scoop.sh -outfile 'install.ps1'

Then run the following command from PowerShell to execute the script as Admin.

.\install.ps1 -RunAsAdmin

Once we run the command, it will start the installation as shown below.

PS C:\Users\Administrator> iwr -useb get.scoop.sh -outfile 'install.ps1'
PS C:\Users\Administrator> .\install.ps1 -RunAsAdmin
Initializing...
Downloading...
Extracting...
Creating shim...
Adding ~\scoop\shims to your path.
Scoop was installed successfully!
Type 'scoop help' for instructions.
PS C:\Users\Administrator>

Step 3:

Next, install Yarn using the scoop command.

scoop install yarn

Here is the installation output.

PS C:\Users\Administrator> scoop install yarn
Installing 'yarn' (1.22.18) [64bit]
yarn-v1.22.18.tar.gz (1.2 MB) [===============================================================================] 100%
Checking hash of yarn-v1.22.18.tar.gz ... ok.
Extracting yarn-v1.22.18.tar.gz ... done.
Linking ~\scoop\apps\yarn\current => ~\scoop\apps\yarn\1.22.18
Persisting cache
Persisting global
Persisting mirror
Running post-install script...
yarn config v1.22.18
success Set "cache-folder" to "C:\\Users\\Administrator\\scoop\\apps\\yarn\\current\\cache".
Done in 0.11s.
yarn config v1.22.18
success Set "yarn-offline-mirror" to "C:\\Users\\Administrator\\scoop\\apps\\yarn\\current\\mirror".
Done in 0.07s.
yarn config v1.22.18
success Set "global-folder" to "C:\\Users\\Administrator\\scoop\\apps\\yarn\\current\\global".
Done in 0.07s.
yarn config v1.22.18
success Set "prefix" to "C:\\Users\\Administrator\\scoop\\apps\\yarn\\current\\global".
Done in 0.07s.
'yarn' (1.22.18) was installed successfully!
PS C:\Users\Administrator>

If Node.js is not already installed, you can do so using the following scoop command.

scoop install nodejs

Here is the output.

PS C:\Users\Administrator> scoop install nodejs
Installing '7zip' (21.07) [64bit]
7z2107-x64.msi (1.8 MB) [=====================================================================================] 100%
Checking hash of 7z2107-x64.msi ... ok.
Extracting 7z2107-x64.msi ... done.
Linking ~\scoop\apps\7zip\current => ~\scoop\apps\7zip\21.07
Creating shim for '7z'.
Creating shortcut for 7-Zip (7zFM.exe)
Persisting Codecs
Persisting Formats
Running post-install script...
'7zip' (21.07) was installed successfully!
Notes
-----
Add 7-Zip as a context menu option by running: "C:\Users\Administrator\scoop\apps\7zip\current\install-context.reg"
Installing 'nodejs' (17.9.0) [64bit]
node-v17.9.0-win-x64.7z (16.6 MB) [===========================================================================] 100%
Checking hash of node-v17.9.0-win-x64.7z ... ok.
Extracting node-v17.9.0-win-x64.7z ... done.
Linking ~\scoop\apps\nodejs\current => ~\scoop\apps\nodejs\17.9.0
Persisting bin
Persisting cache
Running post-install script...
'nodejs' (17.9.0) was installed successfully!
PS C:\Users\Administrator>

Step 4:

Ensure Yarn is installed correctly on the server by checking the version using this command.

yarn --version

It displays the version number as shown below.

PS C:\Users\Administrator> yarn --version
1.22.18
PS C:\Users\Administrator>

How to Install Yarn Using NPM

NPM comes pre-installed with Node.js. It's primarily used to create and share JavaScript code and offers a different way to install Yarn. Follow these steps to install Yarn using NPM.

Step 1:

Open the PowerShell as an Administrator and run the following command to confirm NPM is installed on the server.

npm -version

The output should display the version.

PS C:\Users\Administrator> npm --version
8.5.5
PS C:\Users\Administrator>

Step 2:

Use the below command to install Yarn.

npm install --global yarn

The output is shown below.

PS C:\Users\Administrator> npm install --global yarn

added 1 package, and audited 2 packages in 5s

found 0 vulnerabilities
npm notice
npm notice New minor version of npm available! 8.5.5 -> 8.6.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.6.0
npm notice Run npm install -g npm@8.6.0 to update!
npm notice
PS C:\Users\Administrator>

Step 3:

To check that Yarn installed correctly, check the package version using the following command.

yarn -version

The output shows the version.

PS C:\Users\Administrator> yarn --version
1.22.18
PS C:\Users\Administrator>

Common Yarn Command Potentially Used for Various Tasks

The best way to get a detailed list of information for the yarn command is to use the help option. Below is the syntax to use in the terminal.

yarn help

Start a new project using the following command.

yarn init

In order to install all dependencies for the Yarn project, use one of the following two commands.

yarn

or

yarn install

In order to add a single dependency to a project, use the following syntax, replacing package with the actual package, version with the dependency version, and tag with the appropriate tag for the dependency.

yarn add [package]
yarn add [package]@[version]
yarn add [package]@[tag]

To add dependencies to a specific category, we can use one of the following three options:

  • dev Dependencies.
  • peer Dependencies. 
  • optional Dependencies.

The syntax for adding these command dependencies is as follows.

yarn add [package] --dev
yarn add [package] --peer
yarn add [package] --optional

If you want to upgrade an existing dependency, use the yarn upgrade command.

yarn upgrade [packagename]
yarn upgrade [packagename]@[version]
yarn upgrade [packagename]@[tag]

The yarn remove command is used to remove an existing dependency.

yarn remove [package]

In order to upgrade Yarn to the latest version, run one of the following commands.

yarn set version latest
yarn set version from sources

Wrapping Up

Using this guide helps you with how to install Yarn on your Windows server. Yarn assists you with managing packages and distributing code quickly, securely, and consistently.

If you want to get your Windows server going, Liquid Web offers Windows options for our VPS Hosting, Cloud Dedicated Servers, and Dedicated Servers. Contact our sales team to get set up.

About the Author: Jain Thomas

Jain has been working as a system administrator for the past six years. He loves the excitement and challenge it gives, which keeps him motivated. In addition, he enjoys traveling and is an avid food lover.

Latest Articles

PHP 7 vs PHP 8: A Comparison

Read Article

How to Create a Symbolic Link

Read Article

What Is A Private VPS Parent?

Read Article

Managed Hosting vs Unmanaged VPS Hosting

Read Article

Why Is Your IP Address Blocked?

Read Article