How to install a list of many global packages with Yarn How to install a list of many global packages with Yarn node.js node.js

How to install a list of many global packages with Yarn


Simply type

yarn global add nodejs


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.


For those interested, here's a way to install and manage global applications installed via yarn.

First create a directory which will contain the applications, for example ~/.yarn-global:

mkdir ~/.yarn-globalcd ~/.yarn-global

Then install your application from here:

yarn add yourapp

Finally open your profile file, i.e. .bashrc or .bash_profile and add the path to the bin directory:

export PATH="$PATH:$HOME/.yarn-global/node_modules/.bin"

From now on, any application you install in this directory will be available from anywhere in your shell.

Once this is done, you can even create a yarn-global utility script that will only operate in this .yarn-global directory. For example:

sudo vim /usr/bin/yarn-globalsudo chmod 755 /usr/bin/yarn-global

And the script content would be:

#!/bin/bashcd "$HOME/.yarn-global"yarn $1 "$2"

Now you can do yarn-global add someapp, yarn-global upgrade someapp, etc.