简体   繁体   English

安装“npm install -g ionic cordova”时出错

[英]error while installing "npm install -g ionic cordova"

When I install npm install -g ionic cordova It throws below error当我安装npm install -g ionic cordova It throws below error

npm WARN checkPermissions Missing write access to /usr/lib/node_modules npm ERR! npm WARN checkPermissions 缺少对 /usr/lib/node_modules 的写入权限 npm ERR! path /usr/lib/node_modules npm ERR!路径 /usr/lib/node_modules npm 错误! code EACCES npm ERR!代码 EACCES npm 错误! errno -13 npm ERR! errno -13 npm 错误! syscall access npm ERR!系统调用访问 npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules' npm ERR!错误:EACCES:权限被拒绝,访问 '/usr/lib/node_modules' npm ERR! { Error: EACCES: permission denied, access '/usr/lib/node_modules' npm ERR! { 错误:EACCES:权限被拒绝,访问 '/usr/lib/node_modules' npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/lib/node_modules\'', npm ERR!堆栈:'错误:EACCES:权限被拒绝,访问 \'/usr/lib/node_modules\'',npm ERR! errno: -13, npm ERR!错误号:-13,npm 错误! code: 'EACCES', npm ERR!代码:'EACCES',npm 错误! syscall: 'access', npm ERR!系统调用:'访问',npm ERR! path: '/usr/lib/node_modules' } npm ERR!路径:'/usr/lib/node_modules' } npm 错误! npm ERR! npm 错误! The operation was rejected by your operating system.该操作被您的操作系统拒绝。 npm ERR! npm 错误! It is likely you do not have the permissions to access this file as the current user npm ERR!很可能您没有以当前用户 npm ERR 的身份访问此文件的权限! npm ERR! npm 错误! If you believe this might be a permissions issue, please double-check the npm ERR!如果您认为这可能是权限问题,请仔细检查 npm ERR! permissions of the file and its containing directories, or try running npm ERR!文件及其包含目录的权限,或尝试运行 npm ERR! the command again as root/Administrator (though this is not recommended).再次以 root/Administrator 身份执行该命令(尽管不建议这样做)。

npm ERR! npm 错误! A complete log of this run can be found in: npm ERR!可以在以下位置找到此运行的完整日志:npm ERR!
/home/javauser/.npm/_logs/2018-05-19T04_42_24_737Z-debug.log /home/javauser/.npm/_logs/2018-05-19T04_42_24_737Z-debug.log

I tried with root user as well.我也尝试过使用root用户。 I am using node v9.11.1 , npm 6.0.1我正在使用node v9.11.1 , npm 6.0.1

Never use npm with sudo (or as root)!切勿将 npm 与 sudo(或以 root 身份)一起使用! You can create potential backdoor to your system.您可以为您的系统创建潜在的后门。

I have just answered a very similar question in the following link: How to fix the problem with vue.js instalation我刚刚在以下链接中回答了一个非常相似的问题: How to fix the problem with vue.js instalation

Basicaly what is happening is that NPM does not have the privileges to access /usr/local/lib.基本上发生的事情是 NPM 没有访问 /usr/local/lib 的权限。 To give it access, you could change the ownership of ~/.npm in order to belong to your current user.要授予它访问权限,您可以更改 ~/.npm 的所有权以属于您当前的用户。 This could be this way:这可能是这样的:

sudo chown -R $(whoami) ~/.npm

This way you do not have to run npm as sudo, which is not recomended.这样您就不必将 npm 作为 sudo 运行,这是不推荐的。 I believe that it is due to vulnerabilities that are known in npm packages.我相信这是由于 npm 包中已知的漏洞造成的。

Here is an article about it: Don't use "sudo" with npm "install"这是一篇关于它的文章: 不要在 npm "install" 中使用 "sudo"

run with sudo in Mac OS or linux在 Mac OS 或 linux 中使用 sudo 运行

sudo npm install -g ionic cordova

or in windows open cmd with run as administrator或在 Windows 中以管理员身份运行打开 cmd

npm install -g ionic cordova

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM