简体   繁体   English

执行npm install -g时会发生什么

[英]What happen when npm install -g was executed

this is a very newbie question. 这是一个非常新手的问题。 But I really cannot figure it out through Google search. 但我真的无法通过谷歌搜索找出答案。 I want to understand what happens when one executes 我想了解一个人执行时会发生什么

   sudo npm install -g "node module name"

I understand that the right module will be installed to, normally, /usr/local/.... However, why would this be available globally? 我知道正确的模块将安装到/ usr / local / ....但是,为什么它会在全球范围内可用?

For example, I installed node-inspector locally in my project. 例如,我在我的项目中本地安装了node-inspector But my shell does not understand when I type "node-inspector". 但是当我输入“node-inspector”时,我的shell无法理解。

But once I install it globally, 但是一旦我在全球安装它,

node-inspector & 节点检查员&

command will does the right thing for me. 命令对我来说是正确的。 I really want to understand how this happens. 我真的很想知道这是怎么发生的。

Thanks 谢谢

Quoting the npm's doc : 引用npm的文档

  • Local install (default): puts stuff in ./node_modules of the current package root. 本地安装(默认):将东西放在当前包根目录的./node_modules中。
  • Global install (with -g ): puts stuff in /usr/local or wherever node is installed. 全局安装(使用-g ):将东西放入/usr/local或安装节点的任何位置。
  • Install it locally if you're going to require() it. 如果你想要require()它在本地安装它。
  • 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 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. 这是一个非常简短的描述(我想,这仍然足以看出差异),但链接页面描述了使用npm更详细地安装模块的整个过程。 )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM