what does the "-g" flag do in the command "npm install -g <something>"?

node.jsNpm

node.js Problem Overview


I'm following examples that use the -g flag when using npm install but I can't figure out through the help system what the -g flag is doing.

node.js Solutions


Solution 1 - node.js

-g tells npm to install the named module so that it's accessible globally.

But it's important to understand that -g is typically only used for packages that provide command-line utilities so that their executable components are available in the system PATH.

If you have multiple programs that require the same package, each program should install the package locally. If you really want to share an installed package by installing it globally, you have to also use npm link.

See the docs on the topic of globally installed packages here.

Solution 2 - node.js

If you do npm help install you will see that:

> o npm install (in package directory, no arguments): > > Install the dependencies in the local node_modules folder. > > In global mode (ie, with -g or --global appended to the com- > mand), it installs the current package context (ie, the current > working directory) as a global package.

Solution 3 - node.js

Take the express module as an example. If it was previously installed with the -g option, you could write express anywhere, to create a skeleton application.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontadasajonView Question on Stackoverflow
Solution 1 - node.jsJohnnyHKView Answer on Stackoverflow
Solution 2 - node.jsK ZView Answer on Stackoverflow
Solution 3 - node.jsWerner Kvalem VesteråsView Answer on Stackoverflow