Install node.js and NPM On macOS In Three Easy Methods

Try this guide with our instant dedicated server for as low as 40 Euros

Install Node.js and NPM on Mac

Node.js and NPM (Node Package Manager) are integral tools in modern web development. 

In frontend projects, developers use Node.js to create the JavaScript runtime environment on the server side and create dynamic, scalable web applications. In contrast, NPM is the Node.js package manager that simplifies installing and managing libraries, frameworks, and tools crucial for building web applications. 

Together, Node.js and NPM provide a powerful platform for building fast, efficient, and feature-rich web applications.

In this installation guide, we’ll show you how to install Node.js and NPM on macOS. Then, we’ll go into the details of maintaining these tools on your system. 

Let’s kick off with the prerequisites.

Table of Content

  1. Prerequisites
  2. Check If Node.js and NPM are Installed on Your System
  3. How to Install Node.js and NPM on macOS
  4. Update Node.js and NPM on macOS
  5. Uninstall Node.js and NPM on macOS
  6. FAQs

Prerequisites

You’ll need a system running the latest version of macOS and access to the terminal.

Check If Node.js and NPM are Installed on Your System

Before going into the details of installing these tools, it is always good to check your system to see if they are already installed and available. 

Launch the terminal and enter the following command:

$ node -v

If Node.js is available on your system, you should see the current Node.js version. If that’s not the case, you will see the standard node: command not found error message.

How to Install Node.js and NPM on macOS

You get several options to install Node.js and NPM on macOS. We’ll discuss three methods to help you choose the best fit for your requirements.

Method #1: Use the Official Node.js Installer for macOS

Go to the downloads section of the official Node.js website to get the LTS macOS installer in the PKG format.

node.js installer for mac

We recommend the Long-term Support (LTS) because these installers are better maintained with fewer bugs and thus, adequate for most users. While it is nice to have the latest features, chances are the installer might crash, or you will experience unexpected bugs when using this version for your projects. 

Next, launch the pkg installer and follow the prompts as they appear on your screen. 

Hit Continue on the Introduction screen. 

install node.js

Agree to the license agreement.

license agreement

Choose your installation type and location and click Install.

standard install on macintosh

You’ll be asked for your password to authenticate the installation process. Close the installer when it finishes. 

Method #2: Use HomeBrew to Install Node.js on macOS

Homebrew is perhaps the most popular software package manager for macOS. 

If you don’t have it on your macOS system, we recommend the Redswitches’ guide to installing Homebrew on macOS to bring you up to speed.

Now, launch the terminal and enter the following command to install Node.js and NPM:

$ brew install node

brew install node

During the process, Homebrew will download and install all dependencies. 

Once the installation is complete, verify that the Node.js has been successfully installed on your macOS by looking up the version information with this command:

$ node -v

node -v

Next, use the following command to see the NPM’s version information: 

$ npm -v

npm -v

Method #3: Use nvm to Install and Update Node.js and NPM

If you are a script person, we recommend nvm (Node Version Manager), a bash script used to manage various Node.js versions in the macOS environment.

Launch a fresh terminal and start the nvm install script.

The script adds the source lines to your shell profile, which can be ~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc, and clones the nvm repository to ~/.nvm. You can use curl or wget to get the repository:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

OR

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

wget -qO

Alternatively, you can manually add the source lines. For this, open the shell profile file (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc) in your preferred editor. For this demonstration, we’ll open the zshell shell profile in vi with the following command:

$ vi .zshrc

Next, copy and paste these lines to the file:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "\$NVM_DIR/bash_completion"

# This loads nvm bash_completion

nvm bash_completion

Save the file and exit the editor. 

Return to the terminal and use the following command to reload the shell configuration:

For zshell:

$ source ~/.zshrc

For Bash:

$ source ~/.bashrc

If you want to install a specific version, add the version number to the install command. For instance, run the following command to install version 12.18.0:

$ nvm install v12.18.0

nvm install

If you need the LTS version, run the following command:

$ nvm install --lts

nvm install --lts

Next, run the following command to select the NVM LTS version:

$ nvm use --lts

Alternatively, you can install the latest versions with the following command:

$ nvm install-latest-npm

nvm install-latest-npm

This installs the most recent version of NPM, compatible with the node version you are currently running (this information can be found in ~/.nvm/versions/node/[your-version]/lib/node_modules/npm). 

Update Node.js and NPM on macOS

You can easily update the installed Node.js and NPM versions on your macOS system with Homebrew

However, before that, you should update the Homebrew’s repositories with the following command:

$ brew update. 

Next, run the following command to update the Node.js version:

$ brew upgrade node

brew upgrade node

The above screenshot shows that the test macOS is already running the most recent version of Node.js.

Uninstall Node.js and NPM on macOS

You can easily uninstall both NPM and Node.js from the macOS system with the following command:

$ brew uninstall node

brew uninstall node

Once the command finishes, remove the dependencies with the following command:

$ brew autoremove

Alternatively, you can use the command nvm uninstall ‘node-version’ to remove Node.js from the system.

Also Read: How to Install node.js on Debian: 3 Simple Methods

Conclusion

Installing Node.js and npm on macOS is a straightforward process. We discussed three methods of installing and setting up a Node.js and NPM environment on a macOS system

We also mentioned how to update the current versions on your system and then described how to uninstall these tools from your system. 

If you’re looking for a robust server for your projects, RedSwitches offers the best dedicated server pricing and delivers instant dedicated servers, usually on the same day the order gets approved. Whether you need a dedicated server, a traffic-friendly 10Gbps dedicated server, or a powerful bare metal server, we are your trusted hosting partner.

FAQs

Q. What are Node.js and NPM?

Node.js is an open-source JavaScript runtime environment that allows you to run JavaScript on the server side. NPM (Node Package Manager) is a popular package manager for Node.js, used to install, manage, and share packages/modules.

Q. How do I install Node.js and NPM on macOS?

You can follow these step-by-step instructions to install Node.js and NPM on macOS:

  1. Visit the official Node.js website (nodejs.org) 
  2. For macOS 3, click the “Downloads” button to start the Node.js installer. 
  3. Double-clicking the installer will launch the installation procedure after downloading it. 
  4. To finish the installation, adhere to the directions provided by the installation wizard. 
  5. After Node.js is installed, open a terminal window 
  6. In the terminal, type “node -v” to check the installed version of Node.js 
  7. Next, type “npm -v” to check the installed version of NPM 
  8. If the versions of Node.js and NPM are displayed together, your macOS installation of Node.js and NPM is successful.

Q. Do I need to install Node.js separately if I already have NPM installed?

No, if you have NPM installed on your system, it means Node.js is already installed. NPM is included with Node.js installation.

Q. How do I uninstall Node.js and NPM on macOS?

To uninstall Node.js and NPM on macOS, follow these steps: 1. Open terminal window 2. Type “npm uninstall -g npm” to uninstall the global NPM package 3. Type “brew uninstall node” if you installed Node.js using Homebrew 4. If you installed Node.js manually, navigate to the installation directory and delete it 5. After completing the above steps, Node.js and NPM should be uninstalled from your macOS

Q. How do I check the version of Node.js and NPM?

To check the version of Node.js, open a terminal window and type “node -v”. To check the version of NPM, type “npm -v” in the terminal.

Q. What is a package in the context of Node.js and NPM?

In the context of Node.js and NPM, a package is a collection of JavaScript code and other files intended to be used together as a software development tool or a programming language library. Packages can be installed and managed using NPM.

Q. How do I find a list of packages available on NPM?

You can find a list of packages available on NPM by visiting the official NPM website (npmjs.com) or by using the command “npm search ” in the terminal. Replace it with the keyword related to the package you are looking for.

Q. Can I use Node.js and NPM on both macOS and Windows?

Yes, Node.js and NPM can be used on both macOS and Windows operating systems. The installation process and usage are similar on both platforms.

Q. How do I use Homebrew to install Node.js on macOS?

You can use Homebrew, a popular package manager for macOS, to install Node.js. Follow these steps: 1. Open terminal window 2. Type “brew install node” in the terminal and press Enter 3. Homebrew will download and install the latest version of Node.js on your macOS

Q. What is the purpose of using NPM in Node.js?

NPM plays a crucial role in Node.js development. It allows developers to install and manage external libraries and packages, share their packages with others, and efficiently handle project dependencies.

Try this guide with our instant dedicated server for as low as 40 Euros