Yarn Installation Guide
Yarn 4+ (Modern Version) Installation
Recommended Installation Method (Using Corepack)
Corepack is an intermediary tool that allows you to configure your package manager version on a per-project basis:
# Install Corepack globally
npm install -g corepack
# Initialize a new project (using Yarn Berry)
yarn init -2
Updating Yarn
To update to the latest version at any time, simply run:
yarn set version stable
yarn install
Yarn will then configure your project to use the most recent stable binary.
Using Canary Versions
Yarn frequently ships Release Candidate builds. If you need a feature not yet released on the stable channel:
yarn set version canary
These builds are very stable, with the only difference from the regular channel being a more staggered migration between major versions as new breaking changes are implemented.
Installing Latest Build from Master
If you want to test a Yarn version so recent it hasn't been released in a Release Candidate yet, or even not merged:
# Clone, build, and install from master branch
yarn set version from sources
# Test specific PR
yarn set version from sources --branch 1211
Note: The yarn set version from sources command cannot leverage Corepack and will need to store the Yarn binary inside the .yarn/releases folder and reference it from your project's .yarnrc.yml file.
Yarn Classic (v1) Installation
Installation via npm (Recommended)
It is recommended to install Yarn through the npm package manager, which comes bundled with Node.js:
# Install or upgrade Yarn Classic
npm install --global yarn
Verify Installation
After installation, verify that Yarn is correctly installed by running:
yarn --version
Version Selection Recommendations
- New Projects: Recommended to use Yarn 4+ (modern version) to enjoy the latest features and improvements
- Existing Projects:
- If already using Yarn Classic, you can continue using it
- Consider migrating to modern version for better performance and features
- Enterprise Environments: Modern version provides better workspace support and stability guarantees
System Requirements
- Node.js: All versions require Node.js environment
- npm: Yarn Classic requires npm for global installation
- Corepack: Modern version recommends using Corepack for version management
Note: This document is based on official content from yarnpkg.com and classic.yarnpkg.com websites.
