If you're a Homebrew user and you installed node via Homebrew, there is a major philosophical issue with the way Homebrew and NPM work together.
I assume you have Homebrew. If not, go get it. It’s awesome for OSX. You can install tons of great stuff quickly and efficiently with it. Instructions are at the link or for your convenience, run this:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Run the following commands to remove all existing global npm modules, uninstall node & npm, re-install node with the right defaults, install npm as its own pacakge, and configure the location for global npm modules to be installed.
$ rm -rf /usr/local/lib/node_modules
$ rm -rf ~/.npm
$ brew uninstall node
$ brew install node --without-npm
$ mkdir "${HOME}/.npm-packages"
$ echo NPM_PACKAGES="${HOME}/.npm-packages" >> ${HOME}/.bashrc
$ echo prefix=${HOME}/.npm-packages >> ${HOME}/.npmrc
$ curl -L https://www.npmjs.org/install.sh | sh
Node and npm should be correctly installed at this point. The final step is to add ~/.node/bin
to your PATH
so commands you install globally are usable.
$ echo NODE_PATH=\"\$NPM_PACKAGES/lib/node_modules\:\$NODE_PATH\" >> ${HOME}/.bashrc
$ echo PATH=\"\$NPM_PACKAGES/bin\:\$PATH\" >> ${HOME}/.bashrc
$ echo source "~/.bashrc" >> ${HOME}/.bash_profile
$ source ~/.bashrc
Run these commands to test if you were successful:
//to see the version of node
$ node -v
//to see the version of npm
$ npm -v
//to see the global npm packages you have installed (should just be npm right now)
$ npm list -g --depth=0
Now you can re-install any global packages with the command below without sudo, replacing the npm modules with whatever global packages you need.
$ npm install -g http-server node-inspector forever nodemon grunt-cli gulp bower browser-sync jshint yo
http://www.johnpapa.net/how-to-use-npm-global-without-sudo-on-osx/ https://gist.github.com/DanHerbert/9520689