How to Install NPM and Node.js on Mac

July 31, 2024

Introduction

Node.js is a popular back-end JavaScript runtime for creating web servers and scalable network apps. Node Package Manager (NPM) helps Node.js users manage dependencies, automate workflows, and share reusable code.

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

How to install NPM and Node.js on Mac.

Prerequisites

  • Command-line access.
  • Administrative privileges on the system.

Install NPM and Node.js on Mac Using Homebrew

The recommended way to install Node.js on Mac is via Homebrew, a package manager for macOS. Follow the steps below to learn how to use Homebrew to install, update, and uninstall Node.js and NPM.

Install and Update Homebrew

Before starting the installation, ensure that Homebrew is installed on the system and that the packages are up-to-date:

1. Go to Homebrew's official website and copy the link shown on the page.

Copying the install command for Homebrew on macOS.

2. Paste the command into the terminal. Press Enter to confirm that you want to install Homebrew, and wait for the installation to finish.

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.

3. Update the package list by entering:

brew update
Updating Homebrew in macOS.

Install Node.js and NPM on Mac

With Homebrew installed, follow the procedure below to install Node.js and NPM:

1. Enter the install command:

brew install node

Homebrew downloads and installs Node.js and NPM packages and their dependencies.

Installing Node.js and NPM on macOS using Homebrew.

2. Confirm that you successfully installed Node.js by checking the 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. 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

2. When the update completes, enter the following command:

brew upgrade node

The output in the example shows that the newest version of Node.js has already been 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

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.

Homebrew uninstalls the tools and removes the unneeded formulae.

Install NPM and Node.js on Mac Using PKG Installer

The Node.js website allows users to download a PKG installer and install Node.js and NPM using the macOS GUI. The sections below contain PKG installation instructions.

Download Node.js PKG Installer

Before installing Node.js and NPM with a PKG installer, download the correct file version. Follow the steps below:

1. Go to the official Node.js download page.

2. Choose the Node.js version to download.

3. Select macOS from the list of available operating systems.

4. Select ARM64 or X64 package, depending on your system.

5. Click the Download Node.js button to start the download.

Node.js download page.

Note: The Node.js PKG installer includes NPM.

Run Node.js PKG Installer

Once the download finishes, locate the PKG installer file on the system. Then follow the installation procedure below:

1. Start the installer and select Continue in the Introduction dialog.

Introductory dialog of the Node.js PKG installer.

2. Read the Software License Agreement and select Continue. Confirm that you agree with the terms.

License agreement dialog in the Node.js PKG installer.

3. Click Install in the Installation Type dialog to start the installation.

Starting the installation in the Node.js PKG installer.

4. Wait for the installation to finish, then select Close to exit the installer.

Installation complete in the Node.js PKG installer.

Node.js and NPM are now installed on the system.

Note: To update the PKG version of Node.js, download a newer version and repeat the installation process.

Conclusion

After reading this tutorial, you should know how to install Node.js and NPM on macOS. The article included steps to install Node.js using Homebrew and the official PKG installer.

To learn 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 Update Node.js Version
August 13, 2024

There are several ways to install Node.js and NPM. Similarly, there are several ways to update your Node.js version, depending on the operating system.
Read more
How to Install & Setup MEAN Stack on Ubuntu
March 28, 2024

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.
Read more
MongoDB vs. MySQL
December 31, 2020

From transaction model differences to the quality of support, DBMSs come in all shapes and sizes. Read about the differences between MongoDB and MySQL.
Read more
How to Build a Node.js App with Docker
April 21, 2023

Combining Node.js and Docker helps create a scalable and consistent environment to streamline application deployment.
Read more