I am a big fan of Homebrew and I try to install all of my packages through Homebrew so that I can run updates, checks and installs all using the same commands and directories. I recently started using Node.js quite a big for build systems and also a little bit for server experimentation. One of the things I noticed is that Node isn’t quite as simple to install with Homebrew as most everything else is. There are a few extra steps you must take to get it going correctly, so I thought I would do a brief install tutorial to help anyone out who ran into the same issue.
First off, I am assuming you have Homebrew. If you do not you can check out the Homebrew Website to see what it is, how to get it, etc…You could also just run the following command in terminal to install it really quick:
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
I would also recommend running brew doctor to make sure your system is all good:
Homebrew will spit out some info and some suggestions, you can choose to follow them or move on and come back to that. We will now install Node first.
brew install node
Ok, pretty simple. There is a catch to using Homebrew to install Node, the Node Package Manager doesn’t come along with it from Homebrew, what?!? Pretty lame I thought, but, it’s not so bad. Let’s curl the npm and execute the install script:
curl http://npmjs.org/install.sh | sh
Boom, done. But wait, there’s more. Since we used Homebrew, we need to point the NODE_PATH to the correct place to find Node modules, let’s do that now:
Ok, finally, we need to amend our $PATH since some Node modules have execute files.
Make sure you see “/usr/local/share/npm/bin” in there somewhere. You should be good to go now. To test it out, try installing Twitter Bower (for a lot of node modules you’ll need to run sudo):
sudo npm install -g bower
If that worked, you’re good to go and you can also start using Bower! If that tickled your fancy, try out our (Houndstooth’s) Bootstrap Build Script. Even if you don’t plan to build with Bootstrap itself, the build script we have created runs a system check for things like Homebrew, Git, Node and Bower as well as an optional installer if you like. You could even skip this tutorial entirely and run the setup for our build script and get Node and npm installed in minutes.