Reputation: 2312
I have done this: https://stackoverflow.com/a/21712034
now my npm config is the following:
npm config get prefix
/home/ranu/npm
But when I run npm install -g grunt-cli
I get:
npm ERR! Error: EACCES, mkdir '/usr/lib/node_modules/grunt-cli'
npm ERR! { [Error: EACCES, mkdir '/usr/lib/node_modules/grunt-cli']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/lib/node_modules/grunt-cli',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/lib/node_modules/grunt-cli',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/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 Linux 3.11.0-26-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "-g" "grunt-cli"
npm ERR! cwd /home/ranu
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.14
npm ERR! path /usr/lib/node_modules/grunt-cli
npm ERR! fstream_path /usr/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/lib/node_modules/grunt-cli'
npm ERR! fstream_stack /usr/lib/node_modules/npm/node_modules/fstream/lib/dir- writer.js:36:23
npm ERR! fstream_stack /usr/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! /home/ranu/npm-debug.log
npm ERR! not ok code 0
Why is trying to install it on /usr/lib/node_modules/ if the prefix is set to /home/ranu/npm ?
UPDATE: I could it make it work with the following command:
npm install --prefix="/home/ranu/npm" -g grunt-cli
There is any way to make it as a default?
Upvotes: 1
Views: 373
Reputation: 477
You can use NVM (Node version manager) and you will never have to bother about sudo for npm commands
Upvotes: 1
Reputation: 1345
Every time I get a new Machine, I run into this.
I'm citing this url fixing-npm-permissions because it's actually NPM's doc, but also because it was the only method that fixed my problem. Not the first search result but the simplest fix for me. I'm sure there are more robust fixes.
Rather than copying and pasting, I'm recommending you just go read it.
I followed step 1, and though according to them it should have worked. But, I ended up also using step 2 for the win.
Upvotes: 2