Install Node.js and npm using Homebrew on OS X and macOS

Last updated 4 months ago

Install Node.js and npm with Homebrew

First, install Homebrew.

Bash
/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.

Bash
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.

Bash
brew doctor

Next, add Homebrew’s location to your $PATH in your .bash_profile or .zshrc file.

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

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

Bash
brew install node

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

Bash
npm install -g grunt-cli

All code snippets are licensed GPLv2 or later unless otherwise stated.