How can I update global packages in Yarn?

thibmaek picture thibmaek · Oct 12, 2016 · Viewed 31k times · Source

I tried some possible CLI commands but none seem to actually update the packages installed with yarn global add.

yarn global upgrade & yarn upgrade global both don't work correctly. Is there a way of upgrading global packages?

Answer

Tom Hale picture Tom Hale · Oct 8, 2017

TL;DR:

As webjay says, you simply:

yarn global upgrade

in yarn version 1.2.1 onwards.

For earlier versions:

(cd ~/.config/yarn/global && yarn upgrade)

Checking and repairing

Sadly, there is currently no yarn global check.

You can run yarn global add --force to reinstall all packages.

To check global packages, you can treat ~/.config/yarn/global/ like a local package, since:

  • ~/.config/yarn/global/package.json has dependencies for all global packages
  • ~/.config/yarn/global/node_modules contains all the global packages.

Check all global packages, and reinstall only if an error is found:

$ (cd ~/.config/yarn/global && yarn check || yarn install --force)