What happens when npm install -g is executed… here is a solution to the problem.
What happens when npm install -g is executed
This is a very newbie question. But I really can’t figure it out by googling.
I want to understand what happens when executed
sudo npm install -g "node module name"
I know the correct module is usually installed to /usr/local/….
But why is this available globally?
For example, I installed node-inspector locally in the project. But when I type “node-inspector”, my shell doesn’t understand.
But once I installed it globally,
node-inspector &
The command will do the right thing for me.
I’m really interested to understand how this happened.
Thanks
Solution
Quote the npm’s doc :
- Local install (default): puts stuff in
./node_modules
of the current
package root.- Global install (with
-g
): puts stuff in/usr/local
or
wherever node is installed.- Install it locally if you’re going to
require()
it.- Install it globally if you’re going to run it on the
command line.- If you need both, then install it in both places, or use
npm link
.
This is a fairly brief description (which, I think, is still enough to see the difference), but the link page describes in more detail the entire process of installing modules using npm
. )