Skip to content

Instantly share code, notes, and snippets.

@austinhappel
Last active December 11, 2015 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save austinhappel/4630757 to your computer and use it in GitHub Desktop.
Save austinhappel/4630757 to your computer and use it in GitHub Desktop.
Installing NPM (node package manager) into your home folder. For mac/*nix.

Installing NPM locally (to ~/local instead of /usr/local)

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.


Setting your $PATH

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.


Cleaning up an old npm install

I haven't taken the time to figure this out, but I just did the following and it worked okay:

  1. delete old node_modules folder

     rm -rf /usr/local/lib/node_modules
    
  2. delete any aliases in /usr/local/bin that alias to packages that used to be in /usr/local/lib/node_modules

  3. install everything again using npm and verify that when the -g flag is passed, packages get installed in ~/local/lib/node_modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment