我正在尝试安装Grunt命令行,但我很难安装它。我非常密切地关注了Chris Coyier的演练,并没有看到我出错的地方。我的项目名称是'ryan',这是我的package.json:
{
"name": "ryan",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.2"
}
}
当node_modules安装到项目文件夹中时,Grunt似乎安装得很好。但是,一旦我输入'npm install -g grunt-cli',它似乎就失败了。任何解决方案:
我的终端:
ryans-mbp:ryan rynslmns$ npm install -g grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli
npm http 304 https://registry.npmjs.org/grunt-cli
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/grunt-cli'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/grunt-cli']
npm ERR! errno: 3,
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:37:53',
npm ERR! 'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 13.0.2
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "grunt-cli"
npm ERR! cwd /Users/rynslmns/Desktop/ryan
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.24
npm ERR! path /usr/local/lib/node_modules/grunt-cli
npm ERR! fstream_path /usr/local/lib/node_modules/grunt-cli
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/grunt-cli'
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/rynslmns/Desktop/ryan/npm-debug.log
npm ERR! not ok code 0
答案 0 :(得分:2)
这是因为您正在使用的用户没有权限写入安装了node.js的安装文件夹。
要安装,您需要运行:sudo npm install grunt-cli -g
但我强烈建议在不需要sudo的情况下运行node / npm。有很多方法,这里是一种安装node.js而无需sudo访问的方法:
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install
curl https://npmjs.org/install.sh | sh
访问https://gist.github.com/isaacs/579814了解更多方法(以及我从中复制的方式)。