为什么npm在安装grunt、yeoman等包时老是出错?

小白不太懂,帖出命令行求助!

npm ERR! tar.unpack untar error /Users/xuliang/.npm/grunt-cli/0.1.13/package.tgz
npm ERR! Darwin 14.0.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "-g" "grunt-cli"
npm ERR! node v0.12.0
npm ERR! npm  v2.5.1
npm ERR! path /usr/local/lib/node_modules/grunt-cli
npm ERR! code EACCES
npm ERR! errno -13

npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/grunt-cli'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/grunt-cli']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/grunt-cli',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/grunt-cli',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:46:53',
npm ERR!      'FSReqWrap.oncomplete (fs.js:99: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/xuliang/npm-debug.log
阅读 15.7k
5 个回答

安装过程中没有操作权限,使用管理员身份执行就可以了。
例如 sudo npm install xx

npm ERR! Darwin 14.1.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "-g" "grunt-cli"
npm ERR! node v0.10.36
npm ERR! npm  v2.6.1
npm ERR! path /usr/local/lib/node_modules/grunt-cli/.npmignore
npm ERR! code EACCES
npm ERR! errno 3

npm ERR! Error: EACCES, unlink '/usr/local/lib/node_modules/grunt-cli/.npmignore'
npm ERR!  { [Error: EACCES, unlink '/usr/local/lib/node_modules/grunt-cli/.npmignore']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/grunt-cli/.npmignore' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
npm ERR! error rolling back Error: EACCES, unlink '/usr/local/lib/node_modules/grunt-cli/.npmignore'
npm ERR! error rolling back  { [Error: EACCES, unlink '/usr/local/lib/node_modules/grunt-cli/.npmignore']
npm ERR! error rolling back   errno: 3,
npm ERR! error rolling back   code: 'EACCES',
npm ERR! error rolling back   path: '/usr/local/lib/node_modules/grunt-cli/.npmignore' }

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/kacperwang/git/express/npm-debug.log

这样安装成功了 sudo npm install -g grunt-cli

新手上路,请多包涵

我也遇到了一样的坑,用runas administrator账户就行。
cmd 里面输入runas /user:administrator cmd。
win7默认禁用的 administrator 帐号. lusrmgr.msc 开启

用管理员权限打开cmd命令框就可以了。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进