全局安装 npm [英] Installing npm globally

查看:117
本文介绍了全局安装 npm的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to install npm globally and is this a good idea?

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

I installed npm with the npm install command and was able to run npm start. Then after publishing my project to github I wanted to make sure it would run if someone cloned it, so I cloned it to a different directory on my machine. I then had to run npm install again to install the dependencies. Is it necessary to do this for each project you build locally or is it better and possible to install it globally on your machine?

谢谢

推荐答案

全局安装npm的命令行--

Command line for install npm globally--

npm install -g <package>

此处了解更多信息.

一般来说,经验法则是:

In general, the rule of thumb is:

如果您要安装要在程序中使用的东西,使用 require('whatever'),然后在本地安装它,在根目录下您的项目.

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.

如果你正在安装你想在你的 shell 中使用的东西,在命令行什么的,全局安装,这样它二进制文件最终会出现在您的 PATH 环境变量中.

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.

您可以在此处阅读详细信息.

这篇关于全局安装 npm的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆