6aumug
Last Updated: February 25, 2016
·
4.179K
· extronics
Fa418541c1043189e4b08f4680f25ae3

HowTo: npm global install without root privileges

If you don't want to execute the npm -g with root privileges, here's how to setup npm to support this.

1. Configure npm

npm reads settings from the .npmrc file in your home directory. Create it with the following content:

prefix = ~/.npm

This will tell npm to put all packages, which you install with the -g flag, into .npm/lib/node_modules within your home directory.

2. Configure your $PATH

Some modules (like grunt) come with executable scripts. You probably want to be able to execute them without having to type the full path to .npm/lib/node_modules/.... Thankfully, npm links every executable to .npm/bin. So you just have to add this to your $PATH.

Edit your ~/.bash_profile and add this line:

export PATH=$PATH:~/.npm/bin

That's it.

Say Thanks
Respond