npm install vs sudo npm install -g [英] npm install vs sudo npm install -g

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

问题描述

对于某些软件包,我必须运行 sudo npm install -g 而对于其他软件包,npm install 就足够了.

for some packages I have to run sudo npm install -g while for others npm install will suffice.

为什么和有什么区别?

例如:

npm install -g grunt-cli  # doesn't work
sudo npm install -g grunt-cli  # works
npm install websocket-stream # works

sudo 是否只需要 -g 标志?

Is sudo necessary only with the -g flag?

推荐答案

npm 在本地安装包,即.在当前文件夹内的 node_modules 文件夹中.这允许您的应用程序依赖于特定的软件包版本,而不必弄乱系统上已安装软件包的全局列表.见第一段Isaac 的博文(同时处理同一事物的多个版本),很好地解释了 npm 如何避免在其他编程生态系统中经常遇到的依赖地狱.

npm installs packages locally, ie. in a node_modules folder inside your current folder. This allows your application to depend on specific packages versions, without having to mess up with a global list of installed packages on your system. See the first paragraph of Isaac's blog post (Handle multiple versions of the same thing at the same time), which explains well how npm avoids the dependency hell often encountered in other programming ecosystems.

另一方面,一些包旨在用作命令行实用程序,例如 grunt-climochajson.为了在任何地方使用它们,您需要全局安装它们,因此使用 -g 参数.

On the other hand, some packages are meant to be used as command line utilities, such as grunt-cli, mocha or json. In order to use them everywhere, you need to install them globally, hence the -g parameter.

请注意,您不需要 sudo 来安装全局包,请参阅 此相关答案 了解更多信息.

Please note that you shouldn't need sudo to install global packages, see this relevant answer for more information.

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

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