NPM /自耕农安装​​发电机角没有sudo [英] npm / yeoman install generator-angular without sudo

查看:193
本文介绍了NPM /自耕农安装​​发电机角没有sudo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图安装使用呦( Yoeman )的没有sudo 发电机angularjs:

I tried to install generator-angularjs using Yo (Yoeman) without sudo:

npm install -g generator-angular

我得到:

Error: EACCES, mkdir '/usr/lib/node_modules/generator-angular'

当我键入须藤哟哟告诉我,我不应该使用sudo(这是完全可以理解的)。

When I type in sudo yo, yo tells me that I should not use sudo (which is perfectly understandable).

我有一个〜/ node_modules 目录 - 为什么不哟那里安装了软件包

I have a ~/node_modules directory - why doesn't yo install its packages there?

推荐答案

设计的发电机,以在全球范围内安装。,否则,你总是要安装你准备在每个项目中使用发电机,这是不必要的痛苦。此外,你不会看到可爱的菜单,其中列出了所有可用的发电机(当然,除非你安装它们的所有的本地):

Generators are designed to be installed globally. Otherwise, you always have to install the generator you're about to use in each project, which is unnecessarily painful. Also, you don't get to see the lovely yo menu which lists you all the available generators (unless of course, you install them all locally):

那么,我们如何让故宫在全球范围内安装包?正如你说正确的,你应该永远,永远跑使用sudo。有很多不同的解决方案来这个问题,你可以花时间讨论其利弊宗教。

So, how do we get npm to install packages globally? As you correctly said, you should never, ever run yo with sudo. There are lots of different solutions to this problem and you can spend hours discussing their pros and cons religiously.

我个人不喜欢我安装的用户的包入的全球的/ usr / 文件夹中。 的/ usr / 是在所有用户共享的计算机上的软件。即使它只能使用本机使用,还有尊重Unix文件系统层次结构的设计方式很好的理由。例如,如果你在一个点决定消灭你的整个节点安装。

I personally dislike installing my user packages into the global /usr/ folder. /usr/ is for software that is shared across all users on the computer. Even if it's only using using the machine, there are still good reasons to respect the way the Unix file system hierarchy is designed. For example if you decide at one point to wipe your whole node installation.

我的preferred方式> 的是设置本地节点preFIX 。这是那么容易,因为运行

My preferred way of enabling npm to install packages globally without breaking out of $HOME is to set a local node prefix. This is as easy as running

echo 'prefix = ~/.node' >> ~/.npmrc

在您的本地外壳。在这之后,你要调整你的$ PATH,通过调整你喜欢的shell的配置,以指向新的安装目标为全球节点可执行文件。例如。通过添加

in your local shell. After that, you want to adjust your $PATH, to point to the new installation destination for global node executables by adjusting your favorite shell's config. E.g. by adding

export PATH="$PATH:$HOME/.node/bin"

你的〜/ .bashrc中。在这之后,你可以愉快地运行 NPM安装-g生成角没有sudo,而不会遇到权限冲突,如果事情是完全坏了,要从头开始,所有你需要做的就是删除您的〜/ .node 目录。

to your ~/.bashrc. After that, you can happily run npm install -g generator-angular without sudo, without running into permission conflicts and if something is completely broken and you want to start from scratch, all you need to do is remove your ~/.node directory.

这篇关于NPM /自耕农安装​​发电机角没有sudo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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