node.js 错误:EACCES:权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38323880/
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
提问by xruptronics
I run npm install lodashbut it throws Error: EACCES: permission deniederror. I know it is permission issue but as far as I know, sudo permission is not required for installing node module locally. If I run it with sudo, it gets installed inside ~/node_modules folder. drwxrwxr-xis the file permission of existing folder. I can't figure out what might have gone wrong.
我运行npm install lodash但它抛出错误:EACCES:权限被拒绝错误。我知道这是权限问题,但据我所知,在本地安装节点模块不需要 sudo 权限。如果我使用 sudo 运行它,它会安装在 ~/node_modules 文件夹中。drwxrwxr-x是现有文件夹的文件权限。我无法弄清楚可能出了什么问题。
Below is the error message.
下面是错误信息。
npm ERR! tar.unpack untar error /home/rupesh/.npm/lodash/4.13.1/package.tgz
npm ERR! Linux 3.13.0-88-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "lodash"
npm ERR! node v4.3.1
npm ERR! npm v2.14.12
npm ERR! path /home/rupesh/node_modules/lodash
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir
npm ERR! Error: EACCES: permission denied, mkdir '/home/rupesh/node_modules/lodash'
npm ERR! at Error (native)
npm ERR! { [Error: EACCES: permission denied, mkdir '/home/rupesh/node_modules/lodash']
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/home/rupesh/node_modules/lodash',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/home/rupesh/node_modules/lodash',
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! /home/rupesh/Desktop/es6/npm-debug.log
采纳答案by xruptronics
Creating package.jsonusing npm initsolved my issue.
使用npm init创建package.json解决了我的问题。
回答by Saniya syed qureshi
This command fix the issue. It worked for me:
这个命令解决了这个问题。它对我有用:
sudo npm install -g --unsafe-perm=true --allow-root
回答by Vishal Patel
I have same issue with webpack server installation on globally, Use steps from this UrlSolved my issue, my be work for you.
我在全球范围内安装 webpack 服务器时遇到同样的问题,使用此 Url 中的步骤解决了我的问题,我很乐意为您服务。
Steps mention above There: Back-up your computer before you start.
上面提到的步骤有: 在开始之前备份您的计算机。
Make a directory for global installations:
1.
mkdir ~/.npm-globalConfigure npm to use the new directory path:
2.
npm config set prefix '~/.npm-global'Open or create a ~/.profile file and add this line:
3.
export PATH=~/.npm-global/bin:$PATHBack on the command line, update your system variables:
4.
source ~/.profile
为全局安装创建一个目录:
1.
mkdir ~/.npm-global配置 npm 以使用新的目录路径:
2.
npm config set prefix '~/.npm-global'打开或创建一个 ~/.profile 文件并添加以下行:
3.
export PATH=~/.npm-global/bin:$PATH回到命令行,更新您的系统变量:
4.
source ~/.profile
Test: Download a package globally without using sudo.
测试:不使用 sudo 全局下载包。
npm install -g jshint
Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):
您可以使用相应的 ENV 变量代替步骤 2-4(例如,如果您不想修改 ~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global
回答by Sergey
I had problem on Linux. I wrote
我在 Linux 上遇到了问题。我写
chown -R myUserName ./*
in my project folder.
在我的项目文件夹中。
回答by AJS
From what i can see in your logs you posted:
从我在您发布的日志中看到的内容来看:
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/home/rupesh/node_modules/lodash',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/home/rupesh/node_modules/lodash',
npm ERR! fstream_class: 'DirWriter',
directory /home/rupesh/node_modules/doesn't have necessary permissions to create directory so run chown -r rupesh:rupesh /home/rupesh/node_modules/this should solve it.
directory/home/rupesh/node_modules/没有创建目录所需的权限,因此运行chown -r rupesh:rupesh /home/rupesh/node_modules/它应该可以解决它。
回答by ulittle
This solved my issue straight away - mac Mojave 10.14.6 - PhpStorm.
这立即解决了我的问题 - mac Mojave 10.14.6 - PhpStorm。
Unhandled rejection Error: EACCES: permission denied, mkdir '/Users/myname/.npm/_cacache/index-v5/fb/5a'
未处理的拒绝错误:EACCES:权限被拒绝,mkdir '/Users/myname/.npm/_cacache/index-v5/fb/5a'
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
Original post: https://stackoverflow.com/a/50639828
回答by Courtney Schwartz
FWIW I had the same symptoms, but with a different package. Creating package.jsonand running npm initdid NOTsolve my issue.
FWIW 我有相同的症状,但包装不同。创建package.json和运行npm init并没有解决我的问题。
On this system, apparently new folders in this location were being created with root permissions. During npm install, new folders are created. This caused npm install to fail partway, even with sudo.
在这个系统上,这个位置的新文件夹显然是用 root 权限创建的。在 期间npm install,会创建新文件夹。这导致 npm install 中途失败,即使使用 sudo。
The solution was to run npm install appin a different location with no root umask.
解决方案是npm install app在没有 root umask 的不同位置运行。
回答by Juanjo Salvador
It doesn't have write permissions for others(r-x). Try with
它没有others(rx) 的写权限。试试
chmod a+w <folder>
and repeat.
并重复。
回答by Manohar Reddy Poreddy
A related issue:
一个相关问题:
Wasted 3 hours spanning several days.
浪费了3个小时,跨越了几天。
On a AWS EC2 machine, below worked:
在 AWS EC2 机器上,以下工作:
sudo chown -R $(whoami) /home/ubuntu/.cache
sudo chown -R $(whoami) /home/ubuntu/.config
sudo chown -R $(whoami) /home/ubuntu/.local
sudo chown -R $(whoami) /home/ubuntu/.npm
sudo chown -R $(whoami) /home/ubuntu/.pm2
Hope that helps.
希望有帮助。
回答by Aniruddh Agarwal
I solved this issue by changing the permission of my npm directory. I went to the npm global directory for me it was at
我通过更改 npm 目录的权限解决了这个问题。我去了 npm 全局目录,它位于
/home/<user-name>
I went to this directory by entering this command
我通过输入这个命令进入了这个目录
cd /home/<user-name>
and then changed the permission of .npm folder by entering this command.
然后通过输入此命令更改 .npm 文件夹的权限。
sudo chmod -R 777 ".npm"
It worked like a charm to me. But there is a security flaw with this i.e your global packages directory is accessible to all the levels.
它对我来说就像一种魅力。但是这有一个安全漏洞,即所有级别都可以访问您的全局包目录。

