Install npm into ~/local
instead of usr/local
:
`curl https://npmjs.org/install.sh | npm_config_prefix=~/local sh`
Add this to your ~/.npmrc file:
prefix = ~/local
Now any time you run npm install -g <packagename>
packages will be installed into your home folder at ~/local/lib/node_modules
.
You will most likely have to add ~/usr/local/bin
to your $PATH environment variable. Put this in your .zshrc or .bashrc or whatever newfangled .*rc you use:
export PATH=~/local/bin:$PATH;
This will ensure that globally installed node packages with executables will be available in your command line. (i.e. if you npm install -g grunt-cli
it will run when you type grunt
.
I haven't taken the time to figure this out, but I just did the following and it worked okay:
-
delete old node_modules folder
rm -rf /usr/local/lib/node_modules
-
delete any aliases in
/usr/local/bin
that alias to packages that used to be in/usr/local/lib/node_modules
-
install everything again using npm and verify that when the
-g
flag is passed, packages get installed in~/local/lib/node_modules
.