How to Install Yarn: A Complete Setup Guide for Web Developers
Yarn is a fast, reliable JavaScript package manager developed by Meta as an alternative to npm. It handles dependency management for Node.js projects — installing, updating, and locking packages so every developer on a team works with the same versions. If you're setting up a new project or joining one that uses Yarn, getting the installation right from the start saves headaches later.
What You Need Before Installing Yarn
Yarn runs on top of Node.js, so you need that installed first. Most Yarn versions require Node.js 12 or higher, though Yarn's newer "Berry" release line (v2+) works best with Node.js 14 and above.
You can check whether Node.js is already installed by opening a terminal and running:
node --version If you see a version number, you're ready. If not, download Node.js from the official site (nodejs.org) and install it before continuing.
It's also worth knowing which version of Yarn you're targeting. Yarn Classic (v1) is still widely used and is the default when you install via most package managers. Yarn Berry (v2, v3, v4) is the modern rewrite with different architecture, including the controversial "Plug'n'Play" (PnP) mode that eliminates the node_modules folder entirely.
Installing Yarn Classic (v1) 🛠️
This is the most straightforward path and works on Windows, macOS, and Linux.
Via npm (Recommended Starting Point)
Since you already have Node.js — and therefore npm — the simplest method is:
npm install --global yarn Once installed, confirm it worked:
yarn --version You should see something like 1.22.x. Yarn Classic is now available globally across your system.
Via Corepack (Node.js 16.10+)
Corepack is a Node.js tool that manages package managers without requiring a separate global install. If you're on Node.js 16.10 or newer, this is the cleaner approach:
corepack enable corepack prepare yarn@stable --activate Corepack pins Yarn to your project rather than installing it globally, which reduces version conflicts across projects.
On macOS via Homebrew
If you use Homebrew as your macOS package manager:
brew install yarn Homebrew manages the installation path for you and makes updates easy with brew upgrade yarn.
On Windows via Chocolatey or Scoop
Windows users who prefer a package manager have two common options:
choco install yarn or
scoop install yarn Both handle PATH configuration automatically, which avoids the manual environment variable editing that sometimes trips up Windows users on manual installs.
Installing Yarn Berry (v2, v3, v4)
Yarn Berry isn't installed the same way as Classic. The recommended approach is to initialize it per project rather than installing it globally.
Here's the typical workflow:
- Create or navigate to your project folder
- Initialize a project (if new):
yarn init - Upgrade to Berry:
yarn set version stable
This downloads Yarn Berry into your project and updates the .yarnrc.yml config file. The Yarn binary itself gets committed to your repo (in .yarn/releases/), meaning every developer clones the repo and uses the exact same Yarn version — no global install required.
This approach is fundamentally different from Classic, and whether it fits your workflow depends heavily on your team's setup and tooling compatibility.
Verifying Your Installation
After any installation method, run these two checks:
yarn --version yarn --help If both respond without errors, Yarn is correctly installed and accessible in your terminal's PATH.
For a real-world test, navigate to a project folder and run:
yarn install This reads your package.json and installs all listed dependencies into node_modules (Classic) or resolves them via PnP (Berry). A successful run with no errors confirms everything is working end-to-end.
Key Factors That Affect Which Installation Method Works Best
| Factor | Impact |
|---|---|
| Node.js version | Older Node versions may not support Corepack or Berry |
| Operating system | macOS/Linux have more package manager options; Windows requires extra PATH care |
| Project type | Legacy projects almost always expect Yarn Classic |
| Team setup | Per-project Berry installs reduce version drift on collaborative teams |
| CI/CD environment | Some pipelines are pre-configured for specific Yarn versions |
| Editor/tooling support | PnP mode requires IDE plugins (e.g., VS Code needs a specific SDK setup) |
Common Installation Problems
"yarn: command not found" — Yarn installed but isn't in your PATH. On macOS/Linux, check your shell config file (.bashrc, .zshrc) and ensure the npm global bin directory is included. On Windows, restart your terminal after installation.
Version conflicts between projects — If Project A needs Yarn 1 and Project B uses Yarn 4, global installs create friction. Corepack or per-project Berry installs solve this cleanly.
PnP compatibility errors — Some packages don't fully support Yarn Berry's PnP mode. You can disable it in .yarnrc.yml by setting nodeLinker: node-modules to fall back to the traditional node_modules structure. 🔧
The Variables That Make This Decision Personal
The "right" installation method isn't the same for everyone. A solo developer building a side project in a fresh Node.js environment has very different constraints than a developer joining a team with an existing package.json, a locked Yarn version, and a CI pipeline already configured around it.
Your OS, your Node.js version, whether you're starting fresh or joining an existing codebase, and whether your tooling supports Yarn Berry's PnP mode — all of these shape which installation path actually works smoothly for your situation. Understanding the options is only half the equation; the other half is what your specific setup actually demands. 🧩