这是一个非常新手的问题。但我真的无法通过谷歌搜索弄明白。 我想了解执行时会发生什么
sudo npm install -g "node module name"
我知道正确的模块通常会安装到/usr/local/.... 但是,为什么这会在全局范围内可用?
例如,我在项目本地安装了node-inspector。但是当我输入“node-inspector”时,我的 shell 不理解。
但是一旦我全局安装了它,
node-inspector &
命令会为我做正确的事。 我真的很想了解这是怎么发生的。
谢谢
最佳答案
引用 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
.
这是一个相当简短的描述(我想,这仍然足以看出区别),但是链接页面更详细地描述了使用 npm
安装模块的整个过程。 )
关于linux - 执行 npm install -g 时会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13092747/