3

这是一个非常新手的问题。但我真的无法通过谷歌搜索找到它。我想了解执行时会发生什么

   sudo npm install -g "node module name"

我知道正确的模块通常会安装到 /usr/local/.... 但是,为什么这会在全球范围内可用?

例如,我在项目中本地安装了node-inspector 。但是当我输入“node-inspector”时,我的 shell 不明白。

但是一旦我在全球范围内安装它,

节点检查器 &

命令将为我做正确的事情。我真的很想了解这是怎么发生的。

谢谢

4

1 回答 1

4

Quoting 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.

It's quite a short description (which, I suppose, is still enough to see the difference), but the linked page describes the whole process of installing modules with npm in more details. )

于 2012-10-26T19:00:58.740 回答