JavaScript is one of the most popular programming languages in the world. It is built into most web browsers and used to add interactivity to websites. With Node.js, a “JavaScript runtime,” we can now write JavaScript beyond the browser such as a web server or even on hardware like robots. And with NPM, the package manager used with Node, we can install external modules to help speed up our development.

Note: If you’re on a Windows computer, check out my tutorial for How to Install Node.js and NPM on Windows.

The Node.js site has its own installer, but if you’re working on a Mac, you’re far better off using a package manger like Homebrew to install and manage your software packages.

Install Xcode and Homebrew

The first step is to install Xcode, a free software development tool written by Apple. It is used to build Mac and iOS apps and also compile software. You can install XCode from the App Store. It’s a large program so this might take a while.

Once installation is complete, make sure to also install the Xcode Command Line Tools. On your command line, type the following command and hit Return:

xcode-select --install

Note: The command line is a text-only interface frequently used by developers. You can access it via the Terminal application on any Mac. Go to Finder -> Applications -> Utilities -> Terminal to open it.

Hello World

To install Homebrew, type the following command on the command line and hit Return:

/usr/bin/ruby -e "$(curl -fsSL"

You’ll see messages in the Terminal explaining how to complete the installation setup.

Install Node.js and NPM

Now that we have Xcode and Homebrew, installing Node and NPM–and indeed any software in the future–is straightforward. The following steps should only take a few minutes.

Within your Terminal app, type brew install node. Then sit back and wait: Homebrew will automatically download, unpack, and install the software for us. NPM comes automatically bundled with Node so we only need to install Node itself this way to get both!

  • To confirm Node is installed, type node -v in Terminal. This will print the version number, which will be something like 6.9.5.
  • To confirm NPM is installed, type npm -v in Terminal. The version number should be something like 3.10.10.

How to Update Node and NPM

Node and NPM are updated constantly so it’s likely your version numbers will vary from mine. Fortunately we can use Homebrew to stay up-to-date with all the software it installs.

  • Type brew update in Terminal to update Homebrew itself.
  • Type brew upgrade node to upgrade Node.

How to Uninstall Node and NPM

You can also use Homebrew to uninstall software packages it installed. In Terminal type brew uninstall node to remove it.

Next Steps

Now that Node.js and NPM are installed, learn how to build a web app with Express or how to build a simple REST API with NodeJS.

You can also explore the world of NPM modules to find open-source code to help with almost any project.