How to install Yarn on Windows?

If you are looking for how to install Yarn on Windows operating system, you have come to the right place. Yarn is a fast and secure package manager for JavaScript, and the installation process on Windows is fairly straightforward.

The npm package manager for JavaScript tools and libraries has been around for a long time. However, it suffers from issues such as security, performance, and consistency. The problems become exponential when you plan to use npm for a large concurrency software development project.

However, you can bypass all these issues and access the npm registry using Yarn. In addition, it is a future-ready package manager with robust features and simple commands. Keep reading as we show you how to install yarn packs on your Windows PC from scratch.

What is yarn?

Google, Facebook, Tilde and Exponent have collaborated on a JavaScript package management tool that can replace npm. The project resulted in the Yarn package manager, released as an open source tool in 2016.

Yarn is a new package manager that simplifies and modifies the existing workflow for maintaining and managing JavaScript packages in npm or other package managers. However, the Yarn tool will still support the npm registry for getting pre-programmed JS libraries, tools, etc.

Below you will find the new features of Yarn that make it an indispensable tool for every developer:

  • It downloads and installs JS libraries, tools, packages, etc. faster.
  • Its core engine ensures the integrity, reliability, and version control of installed packages.
  • A simple software development project can include thousands of dependencies. Yarn simplifies your dependency management workflow.
  • It supports mixing registries.
  • Yarn is compatible with Bower and npm workflows.
  • It offers set module license limits.
  • Comes with public JS API for using API data with build tools.
  • Yarn also offers beautiful CLI output, minimal lines of code, and an easy-to-read user interface.

This future-ready package manager has a somewhat similar or simpler DevOps package management process. However, the Yarn tool is very reliable, faster, and extremely secure when compared to Yarn alternatives.

What does yarn do?

Yarn simply solves common package management problems that npm suffers from. Below are some popular features of Yarn:

  • Yarn supports plugins. Users can use Yarn plugins, third-party Yarn plugins, or write their own plugins.
  • The restrictions functionality allows developers to enforce rules and policies on manifest fields or dependencies in scoped workspaces.
  • Yarn allows the programmer to use the offline cache on the local machine with a single file.
  • The Plug'n'Play option allows users to run Node.js projects without the node_modules folder. The resulting Node.js application launches faster compared to applications containing the node_modules folder.
  • The protocol functionality allows developers to define a protocol for resolving packets. For example, you will use the patch protocol to create a patched version of a source package. Another example would be the git protocol for getting public packages from any Git repository.
  • The Release Workflow option helps the software developer to automatically update relevant packages distributed across multiple monorepositories. To do this, the programmer needs to update the root packages, and the Release Workflow does the rest.
  • Yarn Workspaces - intuitive functionality. This allows programmers to install dependencies from multiple package.json files in many subfolders of the same root package.json file at once.

Yarn workflow

Whenever you switch from one package manager to another, the main issue is changing the workflow. Facebook's goal was to create an easy-to-use package manager that supports existing standard workflows from popular package repositories like npm. Consequently, Yarn did not make any major changes. Here is a snapshot of Yarn's main workflow:

  • Create or start a new application development project: yarn init.
  • Adding, removing or updating various dependencies: yarn add [package] upgrade yarn [package] thread remove [package].
  • Installing or reinstalling a code library or dependency: yarn install, yarn install --force, etc.
  • Version control of packages that are created, updated, patched, etc. using Gits.
  • Continuous integration with related tools like AppVeyor, CirleCI, Codeship, Semaphore, Codefresh, etc.

Yarn Benefits

  • Yarn's core engine contains powerful algorithms that allow you to install packages faster. When you download and install thousands of packages in your software project, Yarn installs them in parallel. On the contrary, npm does it one by one. Thus, the project timeline increases dramatically.
  • Yarn allows developers to maintain multiple local cache files for multiple projects. Therefore, using or updating numerous packages for multiple application development projects becomes easy and fast.
  • Tech giants like Facebook, Google, and others support the Yarn community. Hence, you can often find the latest fixes, updates, and new releases.
  • Yarn comes with a detailed migration guide if you are migrating an existing JavaScript development project to Yarn.
  • Yarn guarantees a basic installation on all systems due to its deterministic way of installing operations and lock file format.
  • Yarn ensures the integrity of all imported packages by performing a checksum check.
  • Yarn avoids request cascades when retrieving packages from cloud sources. This process improves the efficiency of the network.

Prerequisites for installing Yarn on Windows

These days, installing a developer runtime and other tools has become an easy task. The process of installing yarn is no different. You can instantly start maintaining and managing JavaScript libraries and dependencies on your Windows machine with Yarn. You just need to enter a few codes and make a few clicks.

Before you can learn how to install Yarn on Windows, you need to make sure your device is properly prepared. For example, consider the following:

  • You need .NET Framework 4.0 or later.
  • Administrative access to the Windows command line.
  • Similarly, you will need administrator access to PowerShell.
  • The latest version of the Node.js runtime is also required to run Yarn.

If you're on a Windows 10 or Windows 11 workstation, logged in as an administrator, then you've taken care of the first three prerequisites. However, learn more about installing Node.js below:

Checking Node.js installation on your Windows machine

No. 1. Click the search icon on your Windows 10 PC and type CMD.

No. 2. You will see the command line application in the "Best match" section.

No. 3. Right-click the command prompt link and select "Run as administrator".

#4: The command line application will open with the following command line output:

C:Windowssystem32>

#5. Now type in the following syntax and press Enter.

node --version

#6: If the CLI output shows that "node" is not recognized as an internal or external command, executable program, or batch file text, it means you need to install Node.js.

Installing Node.js on PC with Windows

No. 1. Visit the Node.js portal to download the latest version.

#2. Choose any version to download under Download for Windows.

No. 3. Double click the Node.js installation package.

#4. Click "Next" once the installer has verified the required space.

#5. You must now accept the End User License and click Next.

#6. Click "Next" again on the "Destination Folder" screen.

#7: Make no changes to the Custom Setup screen. Just click next.

No. 8. Click Next again in the Custom Modules tool and then click Install.

No. 9. After the installation is complete, click Finish.

Install Yarn on Windows with the Yarn MSI Installer

You are now ready to install Yarn on Windows.

Get the Yarn MSI Installer

No. 1. Visit the Yarn download portal.

#2 You should see the text "Click to expand/collapse" under the "Alternatives" heading.

No. 3. Click the drop-down arrow next to the message above to expand the Yarn installation options.

#4: In the Operating System section, select Windows.

No. 5. Select Classic Stable in the Version option.

#6. Now just click on "Download Installer".

Here it is! You should find the Yarn .msi installer in your Downloads folder.

Launching the Yarn MSI Installer

No. 1. Navigate to the Downloads folder on your Windows PC.

#2: Double-click the Yarn installation package.

No. 3. You will see the "Welcome to the Yarn Setup Wizard" screen. Click "Next.

#4: The Yarn Installer will now show the End User License Agreement screen.

#5. On the screen above, check the box for "I accept" and click "Next".

#6. You will now see the destination folder where the Yarn installer installs Yarn. You can leave it as is. Just select Next.

#7. Finally, you are on the Ready to Install screen. Just click "Install" to allow the Yarn MSI installer to install Yarn on Windows.

The process is complete when you see the yarn setup wizard complete. Just click "Done" and you're done.

Verifying Yarn Installation on a Windows PC

No. 1. Open command prompt as administrator.

#2: After CLI C:Windowssystem32> output, type yarn --version.

No. 3. You should see the following script as output:

1.22.19
C:Windowssystem32>

The script above means that you have successfully installed Yarn on your Windows PC. The version of Yarn you have installed is 1.22.19.

Install Yarn on Windows Using a Command Line Application

Experienced developers may not always want to install runtimes or development packages through the MSI installer. Hence, for experienced developers like you, Yarn also offers a command line interface installation. You can follow the steps here:

No. 1. Run the process on a Windows 11 or Windows 10 machine so you don't have to separately install the latest .NET Framework, Command Prompt, PowerShell, etc.

#2: Make sure you already have Node.js installed on this machine. You can verify this by following the steps mentioned above in the Verifying Node.js installation section.

No. 3. If you get CLI output with Node.js version number, it means you already have Node.js.

#4: If you didn't get any version information, you need to install Node.js. You can follow the steps mentioned earlier in Installing Node.js on a Windows PC.

#5: Your Node.js installation should already have Corepack installed. Just activate it using the command line. Run the following command to enable this feature:

corepack enable

#6. After that, you can run the following script on the command line to install Yarn on Windows:

npm install --global yarn

#7. CLI output will add 1 packet and check 2 packets in 1 second on successful installation.

You can check the installed version of Yarn to make sure the installation was successful. Here it is!

Install Yarn on Windows with Scoop

Another convenient way to install Yarn on Windows without running the installer is Scoop. This is a package installer for Windows. The tool works through the PowerShell application. Most experienced developers use Scoop, so it is assumed that you already have it on your Windows system.

If you don't have Scoop on your Windows PC, you can get it from GitHub by following the official installation guide. Access the Scoop Quick Start GitHub portal to install Scoop in minutes.

After that, open the PowerShell app and run the following Scoop command to install Yarn:

scoop install yarn

Scoop will not proceed with the installation if your PC does not have a Node.js runtime. It will prompt you to install it. Here is the command to run:

scoop install nodejs

Install Yarn on Windows with Chocolatey

Experienced developers regularly use Chocolatey to manage Windows packages. If you have it on your computer, you can also install Yarn using Chocolatey.

If you don't have this tool, you can get it from the Chocolatey Installation page. Once Chocolatey is installed, open a command prompt to run the following command, which will automatically install Yarn:

choco install yarn

If you don't have a Node.js runtime, Chocolatey will install it on its own.

Final Words on Installing Yarn on Windows

So far, the article has discussed the basics of Yarn, such as what it is, its benefits, purpose, and more. In addition, you also discovered several ways to install Yarn from scratch.

If you're new to JavaScript development projects, you'll benefit greatly from these steps. You'll cut down on some of the guess work and Google searches on how to install Yarn on Windows, and start maintaining and managing JavaScript packages in Yarn.

Since you are interested in JavaScript development projects, you should familiarize yourself with the best JavaScript (JS) frameworks and JavaScript user interface (JS) libraries.

Related posts