全局安装 npm

Installing npm globally

是否可以全局安装 npm,这是个好主意吗?

我使用 npm install 命令安装了 npm,并且能够 运行 npm start。然后在将我的项目发布到 github 之后,我想确保如果有人克隆它,它会 运行,所以我将它克隆到我机器上的另一个目录。然后我不得不再次 运行 npm install 来安装依赖项。是否有必要为您在本地构建的每个项目执行此操作,还是将其全局安装在您的机器上更好和可能?

谢谢

全局安装 npm 的命令行--

npm install -g <package>

更多信息请阅读 here

In general, the rule of thumb is:

If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project.

If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.

您可以阅读详细信息 here