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:
- Download OSX Node package
- Install the package using the defaults
- 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) - Edit your
~/.bash_profileto include/path/to/your/npm/global/folder/binin 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.