NPM-and-Node.js-on-Mac

Node.js lets you run JavaScript outside a web browser. npm, which is included with Node.js, helps you install and manage packages used by JavaScript projects. On a Mac, you can install both with Homebrew from Terminal or use the official Node.js installer. This guide covers both options. Choose one method for a given installation to avoid confusion about which Node.js version your Mac is using.

Install NPM and Node.js on Mac Using Homebrew

Homebrew is a macOS package manager. It installs command-line software and makes it easier to update or remove later. If you already use Homebrew, start with the update step. Otherwise, install Homebrew first.

Install and Update Homebrew

Open the Terminal app. To install Homebrew, go to the official Homebrew website and copy the current installation command shown there. Paste it into Terminal and press Return. Read the prompts before approving the installation. The script may ask for your Mac login password or to install Apple’s command-line developer tools. Downloading and installing can take a few minutes.

When setup finishes, follow any instructions shown in Terminal to add Homebrew to your shell’s PATH. This lets macOS find the brew command. Then check that Homebrew is available and update its package information:

brew --version
brew update

If Terminal says command not found: brew, revisit Homebrew’s post-install instructions and complete the PATH setup for your shell.

Install Node.js and NPM on Mac

With Homebrew ready, install the Node.js formula:

brew install node

Homebrew installs Node.js and npm together. You do not need a separate npm installation.

Confirm that both commands are available and display their installed versions:

node -v
npm -v

Each command should return a version number. If either command is not found, close and reopen Terminal so it loads the updated PATH. You can also check which executable Terminal is using:

which node
which npm

Update Node.js and NPM on Mac

Homebrew updates its package information with brew update. Then upgrade the Node.js formula:

brew update
brew upgrade node

Because npm is installed with Node.js through this formula, upgrading Node.js through Homebrew also updates the bundled npm version. Check the installed versions afterward:

node -v
npm -v

For projects that require a specific Node.js version, check the project instructions before upgrading. A newer runtime can affect older projects or their dependencies. Node.js publishes release status information and recommends using an LTS release for production applications.

Uninstall Node.js and NPM on Mac

If you installed Node.js with Homebrew, remove the formula with:

brew uninstall node

This removes the Node.js installation managed by Homebrew, including the npm that came with it. Verify that the commands are no longer found, or use which node and which npm to see whether another installation remains on your Mac.

Install NPM and Node.js on Mac Using PKG Installer

The official Node.js download page offers an installer for macOS. The installer provides a graphical setup process and includes npm. Use it if you prefer not to install Node.js through a package manager.

Download Node.js PKG Installer

Open the official Node.js download page. Choose an LTS release unless you specifically need another release for development or testing. The download page may change its layout, so select the current macOS installer option rather than relying on an old version number or screenshot.

Choose the package that matches your Mac’s processor. Apple Silicon Macs use ARM64; Intel Macs use x64. To check your processor, open the Apple menu, select About This Mac, and look for the chip or processor information. Download the .pkg file to your Mac.

Run Node.js PKG Installer

Find the downloaded .pkg file, usually in your Downloads folder, and double-click it. Follow the installer screens: continue past the introduction, review and accept the license, select the standard installation option, and enter your Mac password if requested. When installation completes, close the installer.

Open a new Terminal window and verify that Node.js and npm are available:

node -v
npm -v

Both commands should print a version number. If they are not found, reopen Terminal and try again. If the issue continues, check the installer’s instructions and your shell’s PATH settings. To update this installation later, download a newer macOS PKG from the official Node.js site and run the installer again.

Learn more in the knowledge base on How to install NPM on Windows

Popular Posts You May Read

Explore more hosting insights, tips and industry updates.

How to Add /tmp Security in Centos7?

In this post, we will demonstrate how you can add /tmp security in Centos7. Primarily,…

Dedicated Servers with Mirroring for Data Security

Dedicated Server Mirroring Server mirroring is a process that requires two identical servers at the…

How to Reset the Password for a MySQL Database Client in cPanel

In this post, we’ll look at how to reset the password for a MySQL database…