我可以使用 npm install grunt
在本地安装 gruntjs
。
但是当我尝试全局安装它时 npm install grunt -g
,我得到一个错误:
npm ERR! Error: EACCES, symlink '../lib/node_modules/grunt/bin/grunt'
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR!
npm ERR! System Linux 2.6.18-92.el5xen
npm ERR! command "nodejs" "/usr/bin/npm" "install" "grunt" "-g"
npm ERR! cwd /home/lj
npm ERR! node -v v0.6.18
npm ERR! npm -v 1.1.19
npm ERR! path ../lib/node_modules/grunt/bin/grunt
npm ERR! code EACCES
npm ERR! message EACCES, symlink '../lib/node_modules/grunt/bin/grunt'
npm ERR! errno {}
npm ERR! Error: EACCES, open 'npm-debug.log'
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR!
npm ERR! System Linux 2.6.18-92.el5xen
npm ERR! command "nodejs" "/usr/bin/npm" "install" "grunt" "-g"
npm ERR! cwd /home/lj
npm ERR! node -v v0.6.18
npm ERR! npm -v 1.1.19
npm ERR! path npm-debug.log
npm ERR! code EACCES
npm ERR! message EACCES, open 'npm-debug.log'
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/lj/npm-debug.log
npm not ok
使用 sudo
我也有错误:
npm ERR! Error: spawn ENOENT
npm ERR! at errnoException (child_process.js:483:11)
npm ERR! at ChildProcess.spawn (child_process.js:446:11)
npm ERR! at child_process.js:342:9
npm ERR! at Object.execFile (child_process.js:252:15)
npm ERR! at uidNumber (/usr/lib/nodejs/uid-number/uid-number.js:33:17)
npm ERR! at loadUid (/usr/lib/nodejs/npm/lib/npm.js:336:5)
npm ERR! at Array.2 (/usr/lib/nodejs/bind-actor.js:15:8)
npm ERR! at LOOP (/usr/lib/nodejs/chain.js:15:13)
npm ERR! at /usr/lib/nodejs/chain.js:18:7
npm ERR! at setUser (/usr/lib/nodejs/npm/lib/npm.js:346:32)
npm ERR! 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!
npm ERR! System Linux 2.6.18-92.el5xen
npm ERR! command "nodejs" "/usr/bin/npm" "install" "grunt" "-g"
npm ERR! cwd /home/lj
npm ERR! node -v v0.6.18
npm ERR! npm -v 1.1.19
npm ERR! syscall spawn
npm ERR! code ENOENT
npm ERR! message spawn ENOENT
npm ERR! errno {}
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/lj/npm-debug.log
npm not ok
我可以做些什么来安装它?
附:某些文件夹的权限可能适用于 root:root
,而不适用于我的用户。因为我们的管理员以这种方式安装了 VM...
最佳答案
grunt 和 bower 我也遇到过这个问题
我找到的解决方案在这篇文章 NPM config
在你的 .npmrc 你需要设置前缀路径
prefix = /usr/local
或者您可以像这样从终端执行此操作:
npm config set prefix "/usr/local"
这样 Node 就会知道在哪里安装它们:
在 npm 1.0 中,有两种安装方式:
globally --- 这会将模块放在 {prefix}/lib/node_modules 中,并将可执行文件放在 {prefix}/bin 中,其中 {prefix} 通常类似于/usr/local。它还会在 {prefix}/share/man 中安装手册页(如果提供的话)。
locally --- 这会将你的包安装在当前工作目录中。 Node 模块在 ./node_modules 中,可执行文件在 ./node_modules/.bin/中,并且根本没有安装手册页。
关于javascript - grunt.js 的全局安装失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13527889/