“sudo npm install -g grunt-cli”给我一个错误

当我尝试在Linux 12.04上安装gruntjs时(出现镜像包的源代码),我得到一个错误。

这是错误:

sudo npm install -g grunt-cli npm ERR! Error: ENOENT, open '/home/havetl/.npm/d63f3d0b-grunt-cli.lock' npm ERR! If you need help, you may report this log at: npm ERR! <http://github.com/isaacs/npm/issues> npm ERR! or email it to: npm ERR! <npm-@googlegroups.com> npm ERR! System Linux 3.5.0-23-generic npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "-g" "grunt-cli" npm ERR! cwd /home/havetl npm ERR! node -v v0.10.18 npm ERR! npm -v 1.3.8 npm ERR! path /home/havetl/.npm/d63f3d0b-grunt-cli.lock npm ERR! code ENOENT npm ERR! errno 34 npm ERR! Error: EACCES, open 'npm-debug.log' npm ERR! { [Error: EACCES, open 'npm-debug.log'] errno: 3, code: 'EACCES', path: 'npm-debug.log' } npm ERR! npm ERR! Please try running this command again as root/Administrator. npm ERR! System Linux 3.5.0-23-generic npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "-g" "grunt-cli" npm ERR! cwd /home/havetl npm ERR! node -v v0.10.18 npm ERR! npm -v 1.3.8 npm ERR! path npm-debug.log npm ERR! code EACCES npm ERR! errno 3 npm ERR! stack Error: EACCES, open 'npm-debug.log' npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /home/havetl/npm-debug.log npm ERR! not ok code 0 

感谢您的任何想法!

根据npm的维护者的说法,使用sudo安装软件包被认为是不好的做法,因为你允许这个软件包完全控制你的系统,你不能也不应该信任这些软件包。 考虑到Debian长期的发布周期,作为保护terminal用户免受社区维护软件包的极端例子。

http://howtonode.org/introduction-to-npm

你应该做Issaacsbuild议的内容,并填写你的/usr/local文件夹,这样你有RW权限。

我以前有过这个问题; 有时对于全局包,你当前的工作目录必须是~/ (但我不知道为什么这是!)。 尝试:

 cd ~/; sudo npm install -g grunt-cli 

这个博客为我工作:

http://slopjong.de/2012/10/31/how-to-install-the-latest-nodejs-in-ubuntu/

这个错误是因为在Ubuntu v12中,很less有依赖关系不能用于最新版本的Node。