[英]Error: EACCES: permission denied when trying to install ESLint using npm
I'm trying to install ESLint with npm by going:我正在尝试通过以下方式使用 npm 安装ESLint :
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.老实说,我每次尝试用 npm 安装东西时都会得到这个。 Sometimes using 'sudo' works, sometimes it doesn't... How can I fix this once and for all?
有时使用 'sudo' 有效,有时则无效……我怎样才能一劳永逸地解决这个问题?
Use --unsafe-perm=true
and --allow-root
flags with npm
install like below:-在
npm
install 中使用--unsafe-perm=true
和--allow-root
标志,如下所示:-
sudo npm install -g eslint --unsafe-perm=true --allow-root
it worked like charm for me.它对我来说很有魅力。
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
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
Try this command
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules}
试试这个命令
sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules}
this will change the ownership of the sub-folders used by npm and some other tools (lib/node_modules, bin, and share).
这将更改npm和其他一些工具(lib / node_modules,bin和share)使用的子文件夹的所有权。
Update 更新
Follow this link as suggested by other users. 按照其他用户的建议关注此链接 。
sudo npm install -g --unsafe-perm=true eslint
足够了。
Use sudo before tns and 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:权限被拒绝
you can login as root using sudo su
.您可以使用
sudo su
以 root 身份登录。 First run the command sudo su
on your terminal, then give your login password.首先在您的终端上运行命令
sudo su
,然后提供您的登录密码。 Finally execute your expected command npm install -g eslint
.最后执行您预期的命令
npm install -g eslint
。 It works for me.这个对我有用。
For MAC user provide the access permission to project directory folder对于 MAC 用户提供对项目目录文件夹的访问权限
guys, I have fixed it simplely by伙计们,我已经简单地修复了它
sudo npm install
I have tried the toppest answer, it works well too.我试过最好的答案,它也很好用。
npm install -g @ionic/cli native-run cordova-res
sudo apt update
sudo apt upgrade -y
I had read the already present solutions but thought there was something else, UNSAFE isn't a safe keyword, lol.我已经阅读了已经存在的解决方案,但认为还有别的东西,UNSAFE 不是一个安全的关键字,哈哈。 While running the command with the --unsafe-perm=true, I noticed it downloading what seemed to be update binaries.
在使用 --unsafe-perm=true 运行命令时,我注意到它下载了似乎是更新二进制文件的内容。 So, I updated and tried again.
所以,我更新并再次尝试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.