环境配置工作完成后,在Terminal中安装Yeoman去构建Web应用工具和框架时。
在去创建工程输入命令 yo angular 时报错,如法创建完整的工程。
Error类型如下:
npm ERR! Error: EACCES, open '/home/lizeyi/.npm/async/0.2.10/package/package.json'
npm ERR! at Error (native)
npm ERR! { [Error: EACCES, open '/home/lizeyi/.npm/async/0.2.10/package/package.json']
npm ERR! stack: 'Error: EACCES, open \'/home/lizeyi/.npm/async/0.2.10/package/package.json\'\n at Error (native)',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! path: '/home/lizeyi/.npm/async/0.2.10/package/package.json',
npm ERR! parent: 'grunt-concurrent' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 3.8.0-19-generic
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "update"
npm ERR! cwd /home/lizeyi
npm ERR! node -v v0.11.14-pre
npm ERR! npm -v 1.4.14
npm ERR! path /home/lizeyi/.npm/async/0.2.10/package/package.json
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! stack Error: EACCES, open '/home/lizeyi/.npm/async/0.2.10/package/package.json'
npm ERR! stack at Error (native)
开始以为只是简单的 .json 文件错误。通过简单的拷贝替换其他机器上的 .json文件无法解决此问题。
经程老师指导,最终解决问题。
在应用npm包管理器的时候,强烈建议不要使用sudo 命令,在开发系统上,你可以更改目录的所有权为当前$ USER所以你不必在安装不受信任的代码来运行sudo。否则很容易得到ERR。
这是因为用使用sudo时会影响node.js安装节点。解决方法如下:
首先你需要解锁权限在你的home目录,命令:
sudo chown -R `whoami` ~/.npm
你还需要写权限node_modules目录,如果仍然不能正常工作,可以尝试一下命令:
sudo chown -R `whoami` /usr/local/lib/node_modules
或者
sudo chown -R $USER /usr/lib/node_modules/
如果你仍然看到错误,你可能还需要纠正/usr/local权限,命令:
sudo chown -R `whoami` /usr/local
或者
sudo chown -R $USER /usr/local。
what, no sudo?
I strongly encourage you not to do package management with sudo! Packages can run arbitrary scripts, which makes sudoing a package manager command as safe as a chainsaw haircut. Sure, it’s fast and definitely going to cut through any obstacles, but you might actually want that obstacle to stay there.
I recommend doing this once instead:
sudo chown -R $USER /usr/local
That sets your user account as the owner of the /usr/local directory, so that you can just issue normal commands in there. Then you won’t ever have to use sudo when you install node or issue npm commands.
It’s much better this way. /usr/local is supposed to be the stuff you installed, after all.