InstallationEdit this page on GitHub
The preferred way to manage Yarn is through Corepack, a new binary shipped with all Node.js releases starting from 16.10. It acts as an intermediary between you and Yarn, and lets you use different package manager versions across multiple projects without having to check-in the Yarn binary anymore.
Corepack is included by default with all Node.js installs, but is currently opt-in. To enable it, run the following command:
Corepack isn't included with Node.js in versions before the 16.10; to address that, run:
npm i -g corepack
corepack prepare yarn@stable --activate
Take a look at the latest Yarn release, note the version number, and run:
corepack prepare yarn@<version> --activate
Just run the following command. It will generate some files inside your current directory; add them all to your next commit, and you'll be done!
yarn init -2
Note: By default,
yarn init -2will setup your project to be compatible with Zero-Installs, which requires checking-in your cache in your repository; check your
.gitignoreif you wish to disable this.
Note: In case you're migrating from Yarn 1.x and hit a blocker, you might want to take a look at our Migration Guide. It isn't always needed, but a fairly comprehensive resource of how to solve issues that may arise in the transition.
Any time you'll want to update Yarn to the latest version, just run:
yarn set version stable
Yarn will then configure your project to use the most recent stable binary. Don't forget to run a new install to update your artifacts before committing the results!
From time to time even the most recent releases aren't enough, and you then will want to try out the very latest master branch to check if a bug has been fixed. This has become very simple! Just run the following command:
yarn set version from sources
Similarly, specific PRs can be installed using the
yarn set version from sources --branch 1211