NPM permission issues when not running as root

This is a pretty common issue where you try to run npm install or npm install -g and you get this error saying:

npm ERR! Error: EACCES: permission denied

npm ERR! Please try running this command again as root/Administrator.

Well, this is pretty annoying. But there is a simple way to fix this, on Ubuntu and it should theoretically work on any other Linux/*nix system including OS X. Do comment if it doesn’t work for you.

sudo chown -R $(whoami) ~/.npm

The above code should fix the issue. Make sure the directory you’re working in also belongs to $(whoami) – which pretty much gets replaced by your current username – ubuntu on my server. ┬áThe -R flag means to do it recursively.

I’ve just confirmed that this works on OS X as well, have fun!

Write a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.