Never Install It Globally

Updated August 31, 2022
Created September 23, 2020

You’re sometimes asked to install node packages globally, but this is dangerous and leads to unlisted project dependencies and over-documentation.

If the project requires the package, it should be listed as a dependency. With respect to node, in your devDependencies.

Gatsby prompts for global installation

To ensure all team members have the same running version and there are no mismatches, or additional installation steps in setting up a project, I've done this in the past.

Solution 1

Use npx

npx gatsby-cli <command>


Solution 2

Use yarn

# The only package we can/should install globally
npm install -g yarn
yarn add --save-dev gatsby-cli && yarn gatsby-cli <command>


Solution 3

Use the node binary directly.

npm install --save-dev gatsby-cli && $(npm bin)/gatsby <command>


Solution 4

Add the package as a script.

npm install --save-dev gatsby-cli
#   add to your package.json {"scripts": { "gatsby": "gatsby-cli" }}
#   subsequently
npm run gatsby <command>