Install Node.js and npm using Homebrew on OS X

If you're looking for an easy to follow guide on installing Node.js and npm on OS X, the default method is to download a pre-built installer for your platform, install it, and make sure it's on your $PATH.

But, if you're a Homebrew fan like me and prefer to install all of your packages with it -- ensuring your packages are installed using the same commands and directories and allowing Homebrew to manage updates - this guide will help you get started.

I mostly hang out on Ruby projects -- but since covering Bower, I've been getting familiar with Node and npm so I can play around with Bower, Grunt, and other Node projects.

Install Node.js and npm with Homebrew

First, install Homebrew.

ruby -e "$(curl -fsSL"

Then, brew update to ensure your Homebrew is up to date.

brew update

As a safe measure, run brew doctor to make sure your system is ready to brew. Follow any recommendations from brew doctor.

brew doctor

Next, add the Homebrew location to your $PATH and source your bash or zsh profile file after adding/saving this:

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

Next, install Node (npm will be installed with node):

brew install node

To test out your Node and npm install, try installing Grunt (you might be asked to run with sudo):

npm install -g grunt-cli

If that worked, congrats, you're good to go with Node.js, npm, and Grunt. If not, retrace your steps, or post an issue here.

News Films

Our little film studio focuses on telling developer-centric stories that need to be seen.

Beyond Code: Season 3 / GopherCon 2015

0:00 / 0:00