【问题标题】:Having trouble installing Grunt through the command line通过命令行安装 Grunt 时遇到问题
【发布时间】:2014-02-07 22:42:50
【问题描述】:

我正在尝试安装 Grunt 命令行,但安装时遇到了困难。我非常密切地关注了 Chris Coyier 的演练,看不出我哪里出错了。我的项目名称是“ryan”,这是我的 package.json:

{
  "name": "ryan",
  "version": "0.1.0",
  "devDependencies": {
    "grunt": "~0.4.2"
  }
}

Grunt 似乎安装得很好,因为 node_modules 已安装到项目文件夹中。但是,一旦我输入“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

【问题讨论】:

  • 运行sudo npm install -g grunt-cli 怎么样?

标签: json node.js gruntjs


【解决方案1】:

这是因为您使用的用户没有写入安装 node.js 的安装文件夹的权限。

要安装,您需要运行:sudo npm install grunt-cli -g

但我强烈建议在不需要 sudo 的情况下运行 node/npm。方法有很多,这里有一种无需sudo访问即可安装node.js的方法:

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 了解更多方法(以及我从哪里复制这种方法)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 2019-09-22
    相关资源
    最近更新 更多