1

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?

Community
  • 1
  • 1
elranu
  • 2,292
  • 6
  • 31
  • 55
  • There are 2 `prefix`es used by NPM, [one each for local and global installs](https://www.npmjs.org/doc/files/npm-folders.html). Since you're installing globally, it'll use the global prefix -- `npm config -g get prefix`. Also note that [using `sudo` is generally recommended with NPM](https://github.com/npm/npm#permissions-when-using-npm-to-install-other-stuff). – Jonathan Lonowski Sep 02 '14 at 17:05
  • possible duplicate of [How can I install the grunt-cli without getting errors?](http://stackoverflow.com/questions/20555605/how-can-i-install-the-grunt-cli-without-getting-errors) – Eugene Mayevski 'Callback Sep 02 '14 at 17:05
  • @JonathanLonowski npm config -g get prefix is also /home/elranu/npm – elranu Sep 02 '14 at 17:16
  • @EugeneMayevski'EldoSCorp is not duplicated. They solve the issue using sudo. I want to solve it without using it. – elranu Sep 02 '14 at 17:17

2 Answers2

2

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.

Ryan Ore
  • 1,315
  • 17
  • 23
1

You can use NVM (Node version manager) and you will never have to bother about sudo for npm commands

Anurag Jain
  • 439
  • 5
  • 12