How to Avoid Sudo Npm
You know the story. You try to do
npm install hipster-package on OS X and you get a whole load of errors; the easy way out is to just use
sudo npm install. Everyone, however, keep saying how that is bad idea. But how do you make npm work without sudo? It’s quite simple actually.
On your dev machine
If you are the typical js developer who works on OS X, all you need to do is just change the owner of the node binaries
1 2 3 4 5
If you are working on projects and someone has already checked in a package.json run with sudo, you need to make sure the whole team changes the permissions of at the same time
Unix purists will find this hacky; and rightly so. The proper way of doing is to create a group for everyone who should be allowed to run npm, even if it’s just you. However for a simple dev machine that is good enough.