Install the Node.js global packages as a user, not as root

Written May 22, 2015

Node.js packages should never be installed as root.

How to configure your system to install them as the current user?

$ echo prefix = ~/.node >> ~/.npmrc

Open ~/.bashrc on Linux, or ~/.bash_profile on OSX and add this line at the end of it:

export PATH=$HOME/.node/bin:$PATH

Now everything should be fine! Just run source ~/.bash_profile to run the file and apply the changes in the current terminal session.