Install Node with Homebrew on OS X

Node JS

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:

brew doctor

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:

export NODE_PATH="/usr/local/lib/node"

Ok, finally, we need to amend our $PATH since some Node modules have execute files.

export PATH="/usr/local/share/npm/bin:$PATH"

Now run:

echo $PATH

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.

Houndstooth Bootstrap Build Script

7 Responses to Install Node with Homebrew on OS X

Aaron says: March 13, 2013 at 4:01 am

Brew install npm worked just fine for me

Reply
Rob Bennet says: March 13, 2013 at 10:26 pm

You’re right, it also seems that `brew install node` is also pulling down npm now. When I wrote this, homebrew had removed npm from their repo for some odd reason, so now this post is not needed anymore, but I’ll let it live on in case they decide to get finicky again.

Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>