This tutorial will show you how to install Node.js and NPM on Mac using the Homebrew package manager.
- Access to the terminal
- Administrative level privileges
Node.js has a PKG installer for macOS available on its website. However, installing with Homebrew is the recommended approach.
1. To install Homebrew on macOS, browse to Homebrew's official website and copy the link displayed on the page.
Note: Do not copy the command from the screenshot since it may change in the future. Always visit the website for the up-to-date command.
2. Open the terminal and paste the command. Type the sudo password when prompted. Lastly, confirm that you want to install Homebrew by pressing Return.
Install Node.js and NPM on Mac
1. Type the following command to install Node.js and NPM:
brew install node
Homebrew downloads and installs the dependencies.
2. When the installation finishes, confirm that you successfully installed Node.js by checking its version:
The system displays the Node.js version as the output of the command.
3. Next, check the installed version of NPM by typing:
The NPM version number is displayed.
Update Node.js and NPM on Mac
1. Before you proceed with upgrading the Node.js installation, update Homebrew's repositories by typing:
2. When the update completes, type the following command:
brew upgrade node
The output in the example shows that the newest version of Node.js is already installed on the system.
Note: For additional details, check our article How to Update Node.js and NPM.
Uninstall Node.js and NPM on Mac
1. Uninstall both Node.js and NPM with the
brew uninstall command:
brew uninstall node
2. Remove all the unused dependencies with:
This command removes the packages that
brew uninstall did not remove.
After reading this tutorial, you should know how to use Homebrew to install Node.js and NPM on macOS. If you wish to find out more about the MEAN stack, which features Node.js, read LAMP vs. MEAN: Which is Better?