安装Yo时权限被拒绝

Vin*_*ieu 9 angularjs yeoman yeoman-generator-angular yo

我正在尝试设置你以使用角度生成器进行项目.我按照这里详细说明的步骤进行操作:http://yeoman.io/learning/index.html

我已经安装了Node.js和NPM.

但是当我使用命令时:

sudo npm install -g yo bower grunt-cli
Run Code Online (Sandbox Code Playgroud)

它失败了,我收到了这个错误:

> spawn-sync@1.0.11 postinstall /usr/lib/node_modules/yo/node_modules/cross-spawn/node_modules/spawn-sync
> node postinstall


fs.js:439
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^
Error: EACCES, permission denied '/usr/lib/node_modules/yo/node_modules/cross-spawn/node_modules/spawn-sync/package.json'
    at Object.fs.openSync (fs.js:439:18)
    at Object.fs.writeFileSync (fs.js:978:15)
    at Object.<anonymous> (/usr/lib/node_modules/yo/node_modules/cross-spawn/node_modules/spawn-sync/postinstall.js:20:6)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:935:3
npm ERR! Linux 3.13.0-24-generic
npm ERR! argv "node" "/usr/bin/npm" "install" "-g" "yo"
npm ERR! node v0.10.37
npm ERR! npm  v2.11.0
npm ERR! code ELIFECYCLE

npm ERR! spawn-sync@1.0.11 postinstall: `node postinstall`
npm ERR! Exit status 8
npm ERR! 
npm ERR! Failed at the spawn-sync@1.0.11 postinstall script 'node postinstall'.
npm ERR! This is most likely a problem with the spawn-sync package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node postinstall
npm ERR! You can get their info via:
npm ERR!     npm owner ls spawn-sync
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/vincent/npm-debug.log
Run Code Online (Sandbox Code Playgroud)

我尝试使用chmod 777 on /usr/lib/node_modules但似乎没有更好的效果.

我可以安装Bower和Grunt,它有效,但是当我尝试安装Yo时,它每次都失败了......

我不知道该怎么办,因为我尝试过chmod或者chown没有用过.

谢谢你的帮助!:)

Tre*_*vor 15

我使用以下方法解决了这个问题:

sudo npm install -g yo --unsafe-perm

--unsafe-perm在此错误报告中使用nyakto建议的.

编辑 - 意识到这是@Stephan在他的回答中发布的URL.

我不知道有关--unsafe-perm的具体信息 - 我只能说它允许我安装你没有错误,我经历过与OP非常相似/相同的错误.


Roy*_*M J 9

github repo中的评论解决了我的问题.基本上只需要更新节点版本.列出以后参考的步骤:

sudo npm cache clean -f
sudo npm install -g n
sudo n stable
node -v
Run Code Online (Sandbox Code Playgroud)

干杯