OK, so I finally understand why it’s bad to use sudo npm install.

Here’s how I got a sudo-free install of Node+NPM on OSX:

  1. Download OSX Node package
  2. Install the package using the defaults
  3. Open terminal, and type npm config set prefix /path/to/your/npm/global/folder. The path that you use should be a path that you have full permissions to (e.g. you created/own the folder)
  4. Edit your ~/.bash_profile to include /path/to/your/npm/global/folder/bin in your $PATH (note the /bin)

In my case, I used npm config set prefix /mydev/tools/npm. This sets the location where global NPM packages are dropped.

You need to put the /path/to/your/npm/global/folder/bin location on your path so that the globally-installed packages (e.g. npm install -g grunt) can be executed from the command line using command instead of /path/to/your/npm/global/folder/bin/command.