Reputation: 6901
Inspired by Chris Coyier's post, I decided I'd give grunt a go. But I'm having big problems getting set up.
First, I installed Node.
Then I added a package.json file to my project root, including this:
{
"name": "example-project",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.1"
}
}
Then I ran npm install
Finally, I ran npm install -g grunt-cli
which came back with a ton of errors:
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 11.4.2
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "grunt-cli"
npm ERR! cwd /Users/bryce/repo
npm ERR! node -v v0.10.23
npm ERR! npm -v 1.3.17
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/bryce/repo/npm-debug.log
npm ERR! not ok code 0
Bryce:repo bryce$ 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 11.4.2
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "grunt-cli"
npm ERR! cwd /Users/bryce/repo
npm ERR! node -v v0.10.23
npm ERR! npm -v 1.3.17
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/bryce/repo/npm-debug.log
npm ERR! not ok code 0
I assume the above errors are the reason that when I tried to run grunt
, I simply get -bash: grunt: command not found
Anyone out there know what's happening?
Upvotes: 8
Views: 20702
Reputation: 55
Since you should not install using sudo - you will do this before installing packages and no longer will hit permission errors:
sudo chown -R $USER /usr/local
source: https://howtonode.org/introduction-to-npm
Upvotes: 1
Reputation: 10481
EDIT:
The article quoted below is quite old and refers to pre-v0.3 Yikes! Currently, if npm
is run with sudo
rights it will downgrade to the nobody user before executing commands.
According to the maintainer of npm
, installing packages with sudo
is considered bad practice because you are allowing that package to have complete control of your system and you can't and SHOULDN'T trust these packages with root access.
http://howtonode.org/introduction-to-npm
Upvotes: 9
Reputation: 1
I was having this issue as well, and after reading through the output a little closer i realized that my installed version of node.js was not compatible with the current version of grunt-cli.
Updated node.js problem solved.
Upvotes: 0
Reputation: 6901
All it took was adding 'sudo', since I didn't have permission to install the grunt-cli by default. Once I ran the following command and entered my password, it worked as expected.
sudo npm install -g grunt-cli
Hope this helps someone!
Upvotes: 14
Reputation: 329
I would recommend installing grunt within your project (instead of using the -g option).
For example, to install the Grunt command line tools use:
cd ~/path-to-my-project
npm install grunt-cli --save-dev
If you want to run grunt then you use:
cd ~/path-to-my-project
./node_modules/./bin/grunt
By installing grunt-cli within your project, you'll have full control over which version gets installed and you don't have to rely on inconsistent PATH variables.
Upvotes: 0