How to Install NPM and Node.js on Mac
Node.js is a JavaScript runtime that lets you run JavaScript outside a web browser. It is commonly used for building websites, web applications, APIs, and other server-side applications.
NPM, short for Node Package Manager, comes with Node.js and makes it easier to install and manage the packages your projects need.
If you are using a Mac and want to start working with Node.js projects, you first need to install Node.js and NPM. This guide explains a few simple ways to install them and verify that everything is working correctly.
What Are Node.js and NPM?
Node.js allows JavaScript code to run directly on your computer instead of only inside a browser. Developers use it to build and run applications, development tools, APIs, and other JavaScript-based projects.
NPM is the default package manager for Node.js. It lets you download, update, and manage packages or libraries that can be added to your projects.
When you install Node.js, NPM is normally installed along with it, so you don’t need to install both separately.
How to Install Node.js and NPM on Mac?
There are several ways to install Node.js on macOS. The easiest option for beginners is to use the official Node.js installer. You can also use Homebrew or NVM if you need to work with multiple Node.js versions.
Method 1: Install Node.js Using the Official Installer
This method is straightforward and does not require using Terminal for the installation.
Step 1: Download Node.js
Open your web browser and visit the official Node.js website.
Download the LTS (Long-Term Support) version unless your project specifically requires another release. The LTS version is generally a good choice for stable development environments.
Step 2: Open the Installer
Once the download finishes, open the .pkg file from your Mac’s Downloads folder.
The Node.js installation wizard will appear. Follow the instructions shown on the screen.
Step 3: Complete the Installation
Continue through the installation steps and accept the license agreement when prompted.
Keep the default installation options unless you have a specific reason to change them. Enter your Mac administrator password if macOS asks for permission to install the software.
After the installation finishes, Node.js and NPM should be available from Terminal.
Step 4: Open Terminal
Open Terminal from Applications → Utilities, or search for Terminal using Spotlight.
You can now check whether Node.js was installed correctly.
Run:
node -v
You should see the installed Node.js version.
To check NPM, run:
npm -v
If both commands return version numbers, the installation was successful.
Method 2: Install Node.js Using Homebrew
If you already use Homebrew on your Mac, you can install Node.js directly from Terminal.
Step 1: Check Homebrew
Open Terminal and run:
brew –version
If Homebrew is installed, Terminal will display its version.
Step 2: Install Node.js
Run:
brew install node
Homebrew will download and install Node.js and NPM on your Mac.
Step 3: Verify the Installation
After the installation completes, check both versions:
node -v
and:
npm -v
If version numbers are displayed, Node.js and NPM are ready to use.
Method 3: Install Node.js Using NVM
NVM (Node Version Manager) is useful if you need to switch between different Node.js versions.
This can be helpful when working on several projects that require different Node.js releases.
After installing NVM, you can install an LTS version of Node.js with:
nvm install –lts
Then select that version with:
nvm use –lts
Verify the installation by running:
node -v
and:
npm -v
NVM also makes it easier to install and switch between multiple Node.js versions without replacing the entire installation.
How to Check the Node.js Installation Path?
If you want to know where Node.js is installed, run:
which node
For NPM, use:
which npm
The commands will display the location of the corresponding executable on your Mac.
How to Update Node.js and NPM?
Keeping Node.js updated can help you access newer features, security improvements, and compatibility fixes.
If you installed Node.js using Homebrew, you can update it with:
brew update
brew upgrade node
If you use NVM, you can install a newer LTS release with:
nvm install –lts
NPM can also be updated separately when required:
npm install -g npm@latest
Before updating, check whether your existing projects support the newer Node.js or NPM version.
Troubleshooting Node.js and NPM
If Terminal displays an error such as “command not found” after installation, close and reopen Terminal first. This allows your shell to reload the updated environment.
You can also check the installation path with:
which node
If the command does not return a path, Node.js may not be installed correctly or its location may not be included in your system’s PATH.
If you installed Node.js using NVM, make sure NVM is loaded in your shell configuration before trying the node command again.
Conclusion
Installing Node.js and NPM on a Mac is straightforward, especially when using the official installer. Homebrew provides a convenient option for users who prefer managing software from Terminal, while NVM is a better choice when different projects require different Node.js versions.
Once the installation is complete, use node -v and npm -v to confirm that both tools are available. You can then start creating Node.js applications and install the packages your projects need through NPM.
With a reliable Windows 10 VPS Hosting solution, users can access their development environment remotely and manage applications with greater flexibility and control.
Learn more knowledgebase How to Use SSH on Shared Hosting Plans to Change PHP Version