Important: This documentation covers modern versions of Yarn.
For 1.x docs, see classic.yarnpkg.com.
Yarn
yarn addyarn binyarn cache cleanyarn config getyarn config setyarn config unsetyarn configyarn constraints queryyarn constraints sourceyarn constraintsyarn dedupeyarn dlxyarn execyarn explain peer-requirementsyarn explainyarn infoyarn inityarn installyarn linkyarn nodeyarn npm audityarn npm infoyarn npm loginyarn npm logoutyarn npm publishyarn npm tag addyarn npm tag listyarn npm tag removeyarn npm whoamiyarn packyarn patch-commityarn patchyarn plugin import from sourcesyarn plugin importyarn plugin listyarn plugin removeyarn plugin runtimeyarn rebuildyarn removeyarn runyarn searchyarn set resolutionyarn set version from sourcesyarn set versionyarn stageyarn unlinkyarn unplugyarn upyarn upgrade-interactiveyarn version applyyarn version checkyarn versionyarn whyyarn workspaceyarn workspaces focusyarn workspaces foreachyarn workspaces list

yarn set version

Lock the Yarn version used by the project.

Usage

$> yarn set version <version>

Examples

Download the latest release from the Yarn repository :

yarn set version latest

Download the latest canary release from the Yarn repository :

yarn set version canary

Download the latest classic release from the Yarn repository :

yarn set version classic

Download the most recent Yarn 3 build :

yarn set version 3.x

Download a specific Yarn 2 build :

yarn set version 2.0.0-rc.30

Switch back to a specific Yarn 1 release :

yarn set version 1.22.1

Use a release from the local filesystem :

yarn set version ./yarn.cjs

Use a release from a URL :

yarn set version https://repo.yarnpkg.com/3.1.0/packages/yarnpkg-cli/bin/yarn.js

Download the version used to invoke the command :

yarn set version self

Options

Definition
Description

--only-if-needed

Only lock the Yarn version if it isn't already locked

Details

This command will download a specific release of Yarn directly from the Yarn GitHub repository, will store it inside your project, and will change the yarnPath settings from your project .yarnrc.yml file to point to the new file.

A very good use case for this command is to enforce the version of Yarn used by any single member of your team inside the same project - by doing this you ensure that you have control over Yarn upgrades and downgrades (including on your deployment servers), and get rid of most of the headaches related to someone using a slightly different version and getting different behavior.

The version specifier can be:

  • a tag:

    • latest / berry / stable -> the most recent stable berry (>=2.0.0) release

    • canary -> the most recent canary (release candidate) berry (>=2.0.0) release

    • classic -> the most recent classic (^0.x || ^1.x) release

  • a semver range (e.g. 2.x) -> the most recent version satisfying the range (limited to berry releases)

  • a semver version (e.g. 2.4.1, 1.22.1)

  • a local file referenced through either a relative or absolute path

  • self -> the version used to invoke the command