Install Node.js and npm using Homebrew on OS X and macOS
Use Homebrew to install and update Node.js on Mac
If you’re looking for an easy guide to install Node.js and npm on OS X and macOS — this is it.
Before we get started, are you listening to JS Party? If not, you should be! Maybe start with our episode all about best practices for Node developers. ✊
The default method for installing Node.js is to download a pre-built installer for your platform, install it and make sure it’s on your $PATH
.
However, 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 easily manage upgrades and updates — then this guide will help you get started.
Install Node.js and npm with Homebrew
First, install Homebrew.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Then run brew update
to make sure Homebrew is up to date.
brew update
As a safe measure you should run brew doctor
to make sure your system is ready to brew. Run the command below and follow any recommendations from brew doctor.
brew doctor
Next, add Homebrew’s location to your $PATH
in your .bash_profile
or .zshrc
file.
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 then congratulations — you’ve installed Node.js, npm, and Grunt.
If not — retrace your steps or post a question to Stack Overflow.
Listen to related podcasts on The Changelog
Since you’re interested in Node.js, npm, and Homebrew — listen to some recent related podcasts we’ve done on those subjects.
- #223: Homebrew and Package Management with Mike McQuaid
- #200: JavaScript and Robots with Raquel Vélez, a.k.a. rockbot
- #178: OAuth 2.0, Oz, Node.js, and Hapi.js with Eran Hammer
- #155: The Future of Node.js with Scott Hammond
- #139: The Rise of io.js with Mikeal Rogers
- #119: MEAN.js & Full-Stack JavaScript with Roie Cohen and Amos Haviv
- #116: Node Black Friday at Walmart with Eran Hammer
- #113: Keep npm Running with Isaac Schlueter and Charlie Robbins
- #101: npm Origins and Node.js with Isaac Schlueter
Discussion
Sign in or Join to comment or subscribe