Install Node.js and NPM on a Mac
Note: If you’re on a Windows computer, check out my tutorial for How to Install Node.js and NPM on Windows.
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:
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.
To install Homebrew, type the following command on the command line and hit Return:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
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 -vin Terminal. This will print the version number, which will be something like
- To confirm NPM is installed, type
npm -vin Terminal. The version number should be something like
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.
brew updatein Terminal to update Homebrew itself.
brew upgrade nodeto 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.
Now that Node.js and NPM are installed, learn how to build web applications with Express at ExpressForBeginners.com. We start with a simple “Hello, World” app and quickly progress into building a real-world applications including a message board app, and a robust blog app with user authentication.