How do I change the version of yarn used?

yarn policies set-version <version number>

Per https://github.com/yarnpkg/yarn/issues/7146#issuecomment-477809216


You can use homebrew and yarn formula URLs to install older versions of yarn, then brew switch between yarn versions as needed. Works perfectly! Credit to github user robertmorgan.

  1. First off, if you already have a version installed, unlink it from brew running the brew unlink yarn command in your terminal.

  2. Next, in a web browser, find the Pull Request that has been merged which contained the formula (version) of Yarn that you want to install.

  3. View the files changed in that Pull Request - there should be one for Formula/yarn.rb.

  4. Click the "View" button for the Formula/yarn.rb file to see the whole contents of the file for that commit.

  5. Click the button to view the "Raw" version of that file. This will open a url which should start with https://raw.githubusercontent.com/....

    This is the URL that you will need for the next step - so copy the complete URL to your clipboard.

  6. Back in your terminal window, use the command brew install followed by the URL that you've copied.

    e.g. to install v1.6.0 of yarn it would be:

    brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/fba7635ab69384ac980c635483a7af825bc06088/Formula/yarn.rb
    

You can then verify the versions available to Homebrew by running: brew list --versions yarn, and switch between versions using brew switch yarn VERSION_NUMBER

Source: https://github.com/yarnpkg/yarn/issues/1882#issuecomment-421372892