Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I update global packages in Yarn?

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?

like image 222
thibmaek Avatar asked Oct 12 '16 17:10

thibmaek


People also ask

How do I update my yarn globally?

In order to update your version of Yarn, you can run one of the following commands: npm install --global yarn - if you've installed Yarn via npm (recommended) curl --compressed -o- -L https://yarnpkg.com/install.sh | bash if you're on Unix. otherwise, check the docs of the installer you've used to install Yarn.

How do I update all yarn packages?

just run yarn upgrade-interactive --latest and select packages you want to update using space button and press the enter to update.

How do I add a yarn package globally?

The global command makes executables available to use on your operating system. Note: Unlike the --global flag in npm, global is a command which must immediately follow yarn . Entering yarn add global package-name will add the packages named global and package-name locally instead of adding package-name globally.


3 Answers

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)
like image 94
Tom Hale Avatar answered Oct 22 '22 12:10

Tom Hale


Using yarn global add <package>@latest will upgrade a specific package if that is what you are trying to do.

Update

The recently added yarn global upgrade upgrades all packages. This did not exist at the time of the original answer.

like image 40
cchamberlain Avatar answered Oct 22 '22 13:10

cchamberlain


There has been an issue created for this already at https://github.com/yarnpkg/yarn/issues/776

like image 6
morrislaptop Avatar answered Oct 22 '22 13:10

morrislaptop