gyp WARN EACCES用户"root"没有访问开发目录的权限 [英] gyp WARN EACCES user "root" does not have permission to access the dev dir

查看:57
本文介绍了gyp WARN EACCES用户"root"没有访问开发目录的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试

sudo npm install protractor -g

并再次发生同样臭名昭著的错误/警告(谷歌无济于事):

and the same notorious error/warning again (googled to no avail):

gyp WARN EACCES user "root" does not have permission to access the dev dir "/Users/dmitrizaitsev/.node-gyp/0.12.0"

尽管是我计算机上的当前节点版本,但似乎在同一安装过程中一次又一次地下载并重建了node version 0.12.0:

What seems to happen is that node version 0.12.0 is downloaded and rebuilt, again and again during the same installation, despite of being the current node version on my machine:

node -v
v0.12.0

问题:

  • 目录"/Users/dmitrizaitsev/.node-gyp/0.12.0"实际上丢失了!为什么会有这样的误导性消息?

  • The directory "/Users/dmitrizaitsev/.node-gyp/0.12.0" is actually missing! Why such a misleading message?

为什么在node v0.12.0和先前使用node-gyp成功重建期间都没有创建此目录?

Why was this directory not created neither during the node v0.12.0 nor during the previous successful rebuild with node-gyp?

(很明显)如何防止这种情况发生?

(Obviously) How can I prevent this from happening?

如果这很重要,我将运行Mac OSX 10.8.5.

I run Mac OSX 10.8.5 if that is of any importance.

推荐答案

更新.有一种更好的方法-将npm的默认全局目录更改为您已经具有正确权限的用户子目录,这样就无需首先弄乱系统文件的权限或所有权.

UPDATE. There is a better way - changing npm's default global directory to user sub-directory to which you already have correct permissions, so no need to mess with system file's permissions or ownership in first place.

如推荐 https://docs.npmjs.com/getting-started/fixing-npm-permissions :

  1. 为全局安装创建目录:

mkdir ~/.npm-global

  1. 配置npm以使用新的目录路径:

npm config set prefix '~/.npm-global'

  1. 打开或创建一个~/.profile(或~/.bash_profile等)文件并添加以下行(在文件末尾):
  1. Open or create a ~/.profile (or ~/.bash_profile etc) file and add this line (at the end of the file):

export PATH=~/.npm-global/bin:$PATH

  1. 在命令行上,更新系统变量:

source ~/.profile

source ~/.bash_profile

另请参阅有关该主题的Sindre Sorhus指南: https ://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md

See also Sindre Sorhus's guide on the topic: https://github.com/sindresorhus/guides/blob/master/npm-global-without-sudo.md

现在已经弄清楚出了什么问题:

Have now figured what was wrong:

该目录具有错误的权限-该目录不可可写(与可访问"相比,这是一条更好的错误消息).

The directory had wrong permissions - it was not writable (which would have been a better error message than "accessible").

并且因为它不可写,所以使用了一个临时目录,并在每次使用后将其删除,这就是为什么整个下载必须一次又一次地运行的原因.

And because it was not writable, a temporary directory was used and deleted after every use, which is why the whole download had to run again and again.

解决方案是使用

sudo chown -R $USER <directory>

,再也不会sudo npm. 似乎每当您运行sudo npm时,所有创建的子目录都会获得错误的权限,这将在以后导致问题.

and never sudo npm again. It seems whenever you run sudo npm, all subdirectories created get wrong permissions, which will lead to problems later on.

有关详细信息,请参见此处.

这篇关于gyp WARN EACCES用户"root"没有访问开发目录的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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