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

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

问题描述

尝试

sudo npm install protractor -g

再次出现同样臭名昭著的错误/警告(谷歌搜索无济于事):

gyp WARN EACCES 用户root"无权访问开发目录/Users/dmitrizaitsev/.node-gyp/0.12.0"

似乎发生的是 node 版本 0.12.0 被下载和重建,在同一个安装过程中一次又一次,尽管是我机器上的当前节点版本:

node -vv0.12.0

问题:

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

  • 为什么在 node v0.12.0 和之前使用 node-gyp 成功重建时都没有创建这个目录?

    莉>
  • (显然)我怎样才能防止这种情况发生?

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

解决方案

UPDATE.有一个更好的方法 - 将 npm 的默认全局目录更改为您已经拥有正确权限的用户子目录,因此无需首先弄乱系统文件的权限或所有权.>

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

<块引用>

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

mkdir ~/.npm-global

<块引用>

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

npm 配置设置前缀 '~/.npm-global'

<块引用>

  1. 打开或创建一个 ~/.profile(或 ~/.bash_profile 等)文件并添加这一行(在文件末尾):

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

<小时>

现在已经知道出了什么问题:

目录有错误的权限 - 它不是可写(这会是比可访问"更好的错误消息).

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

解决办法是用

设置用户权限

sudo chown -R $USER <目录>

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

查看此处了解更多详情.

Trying to

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"

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

Questions:

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

  • 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?

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

解决方案

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.

As recommended in https://docs.npmjs.com/getting-started/fixing-npm-permissions:

  1. Make a directory for global installations:

mkdir ~/.npm-global

  1. Configure npm to use the new directory path:

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

  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. On the command line, update your system variables:

source ~/.profile

or source ~/.bash_profile

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.

The solution is to set user permissions with

sudo chown -R $USER <directory>

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.

See here for more details.

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

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