我在学习使用npm install
时,发现有些例子使用 -g
标志,但是我无法通过帮助系统找出这个标志的作用。
-g
告诉 npm
全局安装指定的模块,以便让它在任何地方都可以被访问到。
但重要的是要理解,-g
通常只用于提供命令行工具的软件包,以使其可执行组件在系统的 PATH
中可用。
如果您有多个程序需要使用同一个软件包,则每个程序应该在本地安装软件包。如果想通过全局安装共享已安装的软件包,您还必须使用 npm link
。
有关全局安装软件包的主题文档,请查看此处。
npm help install
,您将看到以下内容:
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.