Setting different Yarn versions in Ubuntu / Linux

10 Feb, 2022

2 Mins Read

This should be a one liner as per the Yarn Docs.

It doesnot work always like that.

The problem

This happens if you have installed the latest version of Yarn. Then and only then one can change Yarn versions. After installing the latest version of Yarn, we can use the old version by setting Yarn to older version.

yarn set version classic

The classic version is 1.x version.

At this point we are good for our projects which use Yarn version 1.x.

When we need to work on something which uses latest version of Yarn, then it should be just setting the Yarn version to latest.

yarn set version latest

Now Yarn will not do the update. However, it shows the message as Why it will not do that.

Warning: Your current Yarn binary is currently Yarn 1.22.15; to avoid potential breaking changes, ‘set version latest’ won’t receive upgrades past the 1.22.x branch. To upgrade to the latest versions, run yarn set version stable instead. Sorry for the inconvenience.

The solution

It is actually said in the Warning.

yarn set version stable

Once this is done, Yarn can do latest. From this point onwards the projects depending on latest version of Yarn will work.

But then sometimes yarn set version stable also will not update the Yarn from classic! This is not a big thing, but may come as a surprise! To fix this, we need to remove some files which are present at ~/ , that is at the UserHome folder. The files are

  • package.json
  • yarn-error.log
  • .yarnrc
  • .yarnrc.yml

Some files might be present, some might not be present. Just remove all the files which are available from this list. And then run the yarn set version command.

This does the trick.