Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

npm

nfs

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?

like image 717
explunit Avatar asked Feb 20 '13 22:02

explunit


People also ask

Where should node modules folder be?

On Unix systems they are normally placed in /usr/local/lib/node or /usr/local/lib/node_modules when installed globally. If you set the NODE_PATH environment variable to this path, the modules can be found by node. Non-global libraries are installed the node_modules sub folder in the folder you are currently in.


1 Answers

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.

like image 100
Pascal Belloncle Avatar answered Nov 11 '22 10:11

Pascal Belloncle