“-g”标志在命令“npm安装-g ”中做什么?

时间:2023-01-18 00:12:21

I'm following examples that use the -g flag when using npm install but I can't figure out through the help system what the -g flag is doing.

我正在跟踪使用npm安装时使用-g标志的示例,但是我无法通过帮助系统了解-g标志在做什么。

3 个解决方案

#1


44  

-g tells npm to install the named module so that it's accessible globally.

-g告诉npm安装命名模块,以便全局访问。

But it's important to understand that -g is typically only used for packages that provide command-line utilities so that their executable components are available in the system PATH.

但重要的是要理解-g通常只用于提供命令行实用程序的包,以便它们的可执行组件在系统路径中可用。

If you have multiple programs that require the same package, each program should install the package locally. If you really want to share an installed package by installing it globally, you have to also use npm link.

如果有多个程序需要相同的包,那么每个程序都应该在本地安装这个包。如果您真的希望通过全局安装来共享已安装的包,您还必须使用npm链接。

See the docs on the topic of globally installed packages here.

请参阅本文中关于全局安装包的文档。

#2


14  

If you do npm help install you will see that:

如果你做npm帮助安装,你会看到:

  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.

#3


2  

Take the express module as an example. If it was previously installed with the -g option, you could write express anywhere, to create a skeleton application.

以express模块为例。如果它之前安装了-g选项,您可以在任何地方编写express来创建一个框架应用程序。

#1


44  

-g tells npm to install the named module so that it's accessible globally.

-g告诉npm安装命名模块,以便全局访问。

But it's important to understand that -g is typically only used for packages that provide command-line utilities so that their executable components are available in the system PATH.

但重要的是要理解-g通常只用于提供命令行实用程序的包,以便它们的可执行组件在系统路径中可用。

If you have multiple programs that require the same package, each program should install the package locally. If you really want to share an installed package by installing it globally, you have to also use npm link.

如果有多个程序需要相同的包,那么每个程序都应该在本地安装这个包。如果您真的希望通过全局安装来共享已安装的包,您还必须使用npm链接。

See the docs on the topic of globally installed packages here.

请参阅本文中关于全局安装包的文档。

#2


14  

If you do npm help install you will see that:

如果你做npm帮助安装,你会看到:

  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.

#3


2  

Take the express module as an example. If it was previously installed with the -g option, you could write express anywhere, to create a skeleton application.

以express模块为例。如果它之前安装了-g选项,您可以在任何地方编写express来创建一个框架应用程序。