How to install a list of many global packages with Yarn

yarn install -h suggests that the -g (global) option is DEPRECATED. How am I supposed to indicate that I want a bunch of packages (from package.json / yarn.lock files) to be installed globally?

Options I saw:

  • yarn global [command] has things such as ls and add but not install. add only works with particular package names, if I understand correctly. I already have my yarn.lock file ready, I don't want to repeat myself on the command line.
  • yarn global add each package one by one. Now my list of packages would be imperative instead of declarative.

Specifically, I'd like to use one executable from one of those packages.


Solution 1:

Simply type

yarn global add nodejs

Solution 2:

How am I supposed to indicate that I want a bunch of packages (from package.json / yarn.lock files) to be installed globally?

You shouldn't. Installing globally is discouraged by Yarn, and there are very few situations where it's necessary, or even helpful.

As noted in the documentation:

For the vast majority of packages it is considered a bad practice to have global dependencies because they are implicit. It is much better to add all of your dependencies locally so that they are explicit and anyone else using your project gets the same set of dependencies.

If you are trying to use a CLI tool that has a bin you can access these in your ./node_modules/.bin directory.

But I really, really want to!

If you really don't want to listen to the advice given, use

yarn global add <package>

However, don't expect to easily install a huge list of dependencies globally—it's hard to do by design, because it's not a good idea.


Instead, the intended flow with Yarn is:

  • install everything locally, so each project is isolated
  • call binaries from ./node_modules/.bin where possible
  • avoid global installs—they're a convenience, but not one you should rely on.