Skip to content

Instantly share code, notes, and snippets.

@tomysmile
Last active October 9, 2015 22:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomysmile/da3cb8194ec8f0e4df86 to your computer and use it in GitHub Desktop.
Save tomysmile/da3cb8194ec8f0e4df86 to your computer and use it in GitHub Desktop.
Node: Install NodeJS on Mac OSX.md

Install NodeJS and NPM On Mac OS X for Homebrew Users

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.

Homebrew

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)"

Install Node

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

Verification

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

References

http://www.johnpapa.net/how-to-use-npm-global-without-sudo-on-osx/ https://gist.github.com/DanHerbert/9520689

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