How to Install Node.js and NPM on Mac

September 9, 2021

Introduction

Node.js is a popular back-end JavaScript runtime used for creating web servers and scalable network apps. The environment supports server-side scripting - producing dynamic content for web pages before they are served to the user.

NPM is a package manager for JavaScript and the default package manager for Node.js. As such, NPM is installed alongside Node.js as a recommended feature.

This tutorial will show you how to install Node.js and NPM on Mac using the Homebrew package manager.

How to Install Node.js and NPM on Mac

Prerequisites

  • Access to the terminal
  • Administrative level privileges

Note: Node.js has a PKG installer for macOS available on its website. However, installing with Homebrew is the recommended approach.

Install Homebrew

1. To install Homebrew on macOS, browse to Homebrew's official website and copy the link displayed on the page.

Copying the install command for Homebrew on MacOS

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.

Installing Homebrew on MacOS

Install Node.js and NPM on Mac

Note: For other operating systems, refer to our tutorials on installing Node.js and NPM on Windows, Ubuntu, and CentOS.

1. Type the following command to install Node.js and NPM:

brew install node

Homebrew downloads and installs the dependencies.

Installing Node.js and NPM on MacOS using Homebrew

2. When the installation finishes, confirm that you successfully installed Node.js by checking its version:

node -v

The system displays the Node.js version as the output of the command.

Checking the version of the Node.js installation on MacOS

3. Next, check the installed version of NPM by typing:

npm -v

The NPM version number is displayed.

Checking the version of the NPM installation on MacOS

Update Node.js and NPM on Mac

1. Before you proceed with upgrading the Node.js installation, update Homebrew's repositories by typing:

brew update
Updating Homebrew in MacOS

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.

Upgrading the Node.js and NPM installation with Homebrew on MacOS

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
Uninstalling the Node.js and NPM installation with Homebrew on MacOS

2. Remove all the unused dependencies with:

brew autoremove
Removing the unused dependencies with Homebrew on MacOS

This command removes the packages that brew uninstall did not remove.

Conclusion

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?

Was this article helpful?
YesNo
Marko Aleksic
Marko Aleksić is a Technical Writer at phoenixNAP. His innate curiosity regarding all things IT, combined with over a decade long background in writing, teaching and working in IT-related fields, led him to technical writing, where he has an opportunity to employ his skills and make technology less daunting to everyone.
Next you should read
How To Install Node.js & NPM on Ubuntu 18.04 and 20.04
March 18, 2019

Node.js is an open-source cross-platform JavaScript (JS) runtime environment. It is used for building fast and scalable network applications. In addition to offering various JS modules, it is also...
Read more
How to Install & Setup MEAN Stack on Ubuntu
April 9, 2019

MEAN stack comes as an alternative to the widely known LAMP stack, which uses JS on the client side, but PHP on the server side. In this article, you will find step-by-step instructions on how to install the MEAN stack...
Read more
MongoDB vs. MySQL
December 31, 2020

From transaction model differences to the quality of support, DBMSs come in all shapes and sizes. In this comparison article, you will read about the differences between the two popular DBMS solutions: MongoDB and MySQL.
Read more
How to Install Yarn on Ubuntu 18.04
September 11, 2019

Yarn is a tool for managing, updating, and sharing your Java code. Yarn works through node.js helping to track libraries, dependencies, and even enables you to share solutions with other developers.
Read more
  • © 2021 Copyright phoenixNAP | Global IT Services. All Rights Reserved.