node.js 错误:EACCES:尝试使用 npm 安装 ESLint 时权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35954725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error: EACCES: permission denied when trying to install ESLint using npm
提问by DHRUV GUPTA
I'm trying to install ESLintwith npm by going:
npm install -g eslint
However I get the following error:
但是我收到以下错误:
Deans-Air:~ deangibson$ npm install -g eslint
npm ERR! tar.unpack untar error /Users/deangibson/.npm/eslint/2.4.0/package.tgz
npm ERR! Darwin 15.3.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "eslint"
npm ERR! node v4.2.3
npm ERR! npm v2.14.7
npm ERR! path /usr/local/lib/node_modules/eslint
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/eslint'
npm ERR! at Error (native)
npm ERR! { [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/eslint']
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/eslint',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/eslint',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:35:25',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:47:53',
npm ERR! 'FSReqWrap.oncomplete (fs.js:82:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/deangibson/npm-debug.log
And to be honest I get this every single time I try and install something with npm. Sometimes using 'sudo' works, sometimes it doesn't... How can I fix this once and for all?
老实说,每次我尝试使用 npm 安装一些东西时,我都会得到这个。有时使用“sudo”有效,有时则无效……我该如何一劳永逸地解决这个问题?
回答by DHRUV GUPTA
Use --unsafe-perm=trueand --allow-rootflags with npminstall like below:-
使用--unsafe-perm=true和安装--allow-root标志npm如下:-
sudo npm install -g eslint --unsafe-perm=true --allow-root
it worked like charm for me.
它对我来说很有魅力。
回答by Mobiletainment
This problem is well documented in the npm docs: Fixing npm permissions.
这个问题在npm 文档中有详细记录:修复 npm 权限。
You have 2 solutions available:
您有 2 个可用的解决方案:
Option 1: Change npm's default directory to a hidden directory in your home folder
选项 1:将 npm 的默认目录更改为您的主文件夹中的隐藏目录
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.profile
Option 2: Use a package manager that takes care of this for you
选项 2:使用为您处理此问题的包管理器
brew install node
回答by mahmoud mehdi
Running the following command solved the issue for me while installing my packages.json :
运行以下命令在安装我的 packages.json 时为我解决了这个问题:
sudo npm install --unsafe-perm=true --allow-root
To install only the package which caused the issue:
仅安装导致问题的软件包:
sudo npm install -g --unsafe-perm=true --allow-root eslint
回答by Abhijeet Jadhav
Use sudo before tnsand it is work for me
在 tns 之前使用sudo对我有用
Example:
例子:
sudo tns create Tekmo --template tns-template-hello-world
if I have used sudo then not found error like to create postinstall.js
如果我使用过 sudo 然后没有发现错误,比如创建postinstall.js
Error: EACCES: permission denied
错误:EACCES:权限被拒绝
回答by Rahul
sudo npm install -g --unsafe-perm=true eslint
is sufficient.
足够了。
回答by snr
sudo npm install -g eslint --unsafe-perm=true --allow-root
is sufficient to run.
足以运行。
回答by Nandu Hulsure
For MAC user provide the access permission to project directory folder
对于 MAC 用户提供对项目目录文件夹的访问权限
- Right click on project directory folder
- Select get info
- Provide the access permission - Apply to inclosed items
- 右键单击项目目录文件夹
- 选择获取信息
- 提供访问权限 - 应用于封闭项目

