是什么原因导致错误:EACCES:权限被拒绝,访问'/usr/local/lib/node_modules'?
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/macbookmd101/.npm/_logs/2018-02-21T16_26_08_421Z-debug.log
注意所有更改/usr/local下所有目录所有者的响应
基本上,不要破坏Linux系统!!
对于本地的东西使用sudo也是一个非常糟糕的建议。
www.competa.com的原始链接被破坏了,所以这是原始的方法:
npm config set prefix ~/.npm
# open your .bashrc (Linux) or .bash_profile (Mac) file for editing:
nano ~/.bashrc # for Linux
# or...
nano ~/.bash_profile # for Mac if you haven't created a .bashrc file
# add these lines:
export PATH="$PATH:$HOME/npm/bin"
export NODE_PATH="$NODE_PATH:$HOME/npm/lib/node_modules"
# save the file and then enter this command or logout and login to make the changes take effect:
. ~/.bashrc
# or...
. ~/.bash_profile
选项B:使用NVM之类的版本管理器
看来你遇到许可问题了。如果您正在安装npm-packages,那么在尝试全局安装包时可能会得到EACCES错误。这意味着你没有权限写入npm用来存储全局包和命令的目录。
尝试执行命令:sudo chmod u+x -R 775 ~/。npm和sudo chown $USER -R ~/。或者你可以用sudo运行任何NPM命令,这应该能解决你的问题。
如果你在本地安装npm-package,那么你应该在你的本地项目目录下,可以尝试运行sudo npm install <pkg-name>命令来安装所需的包。使用sudo的目的是改变你的所有者权限,这样你就可以授权你的当前用户运行NPM命令。
我建议你去https://docs.npmjs.com/getting-started/fixing-npm-permissions看看