If you’re looking for an easy guide to install Node.js and npm on OS X and macOS — this is it.
In order to provide the best performance (and other optimisations), nvm will download and install pre-compiled binaries for Node (and npm) when you run nvm install X. The Node project compiles, tests and hosts/provides these pre-compiled binaries which are built for mainstream/traditional Linux distributions (such as Debian, Ubuntu, CentOS. Fortunately, for Windows users, the Node.js® installation process is a lot easier than how I recommend installing Node.js® on a Mac. Node isn’t a program that you simply launch like Word or Photoshop: you won’t find it pinned to the taskbar or in your list of Apps. Updating Node.js on Windows and macOS follows the same principles. There are two simple ways to upgrade: Download the latest Node.js release from its official download page and install the new Node.js release. Install the n module and update Node.js inside the terminal window.
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.
Then run brew update
to make sure Homebrew is up to date.
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.
Next, add Homebrew’s location to your $PATH
in your .bash_profile
or .zshrc
file.
Next, install Node (npm will be installed with Node):
To test out your Node and npm install, try installing Grunt (you might be asked to run with sudo):
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.
What’s Node.js® and NPM?
Node.js® is a JavaScript-based environment which you can use to create web-servers and networked applications. You can also use it to perform helpful tasks on your computer such as concatenating and minifying JavaScript files and compiling Sass files into CSS.
NPM is a “package manager” that makes installing Node “packages” fast and easy. A package, also called a module, is just a code library that extends Node by adding useful features. For example, the “request” module simplifies the process of making HTTP requests so you can easily get web resources from other sites.
NPM is installed when you install Node.js®
Although there is a Mac installer program on the Node website, we recommend using Homebrew to install and update Node.
Prerequisites
- You should have some familiarity with the Mac Terminal application since you’ll need to use it to install and test Node and NPM. You’ll also need the Terminal to use Node.js and NPM. The Terminal application is located in the Utilities folder in the Applications folder.
- Dependencies. Although you can install Node in other ways, we recommend using Homebrew. Homebrew lets you avoid possible security problems associated with using the
sudo
command to install software like Node and Node modules.- Install Homebrew. Follow the steps on the How to Install Homebrew on a Mac instruction guide to install Homebrew.
Installation Overview
Installing Node.js® and NPM is pretty straightforward using Homebrew. Homebrew handles downloading, unpacking and installing Node and NPM on your system. The whole process (after you have Homebrew installed) should only take you a few minutes.
Installation Steps
- Open the Terminal app and type
brew update
. This updates Homebrew with a list of the latest version of Node. - **Type
brew install node
. - Sit back and wait. Homebrew has to download some files and install them. But that’s it.
Test it!
Make sure you have Node and NPM installed by running simple commands to see what version of each is installed:
- Test Node. To see if Node is installed, type
node -v
in Terminal. This should print the version number so you’ll see something like thisv0.10.31
. - Test NPM. To see if NPM is installed, type
npm -v
in Terminal. This should print the version number so you’ll see something like this1.4.27
How to Update Node and NPM
New versions of Node and NPM come out frequently. You can use Homebrew to update the software it installs.
Node Js Install Mac Tutorial
- Make sure Homebrew has the latest version of the Node package. In Terminal type
brew update
- Upgrade Node:
brew upgrade node
How to Uninstall Node and NPM
You can use Homebrew to uninstall packages that it installed:
Node Js Install On Mac Virtualbox
brew uninstall node