Search code examples
node.jsnpmnfs

alternate location for .npm folder (to avoid NFS-mounted home)


I have an NFS-mounted home folder and am trying to set up global packages via npm, for example:

sudo npm install -g jshint

This gives me an error because under sudo I can't create anything on the remote server (tried this outside of npm)

npm ERR! Error: EACCES, open '/home/explunit/.npm/a02a2468-jshint.lock'
npm ERR!  { [Error: EACCES, open '/home/explunit/.npm/a02a2468-jshint.lock']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/home/explunit/.npm/a02a2468-jshint.lock' }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.

I'm sure somebody will come along in 2 minutes and say "don't use sudo -- a real developer would understand how to set up node/npm without it!", but a) it's never been clear to me how this is designed to work, given that the npm readme suggests sudo, and b) in this case I really don't want anything tied to my specific user (it's a build server)

So I guess the real question is how to make npm ignore my home folder and use some other location for .npm?


Solution

  • Try to change where the cache is with this.

    npm config set cache /SOMEWHERE/ELSE
    

    /SOMEWHERE/ELSE should be somewhere where the user running the command can write.