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.
Written by Johannes Klose
Related protips
Have a fresh tip? Share with Coderwall community!
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside