Node.js lets you run JavaScript outside the browser, while npm is the package manager that is installed automatically with Node.js. For macOS, the easiest options are the official .pkg installer or Homebrew.
Choose an Installation Method
| Method | Best for | Main command |
|---|---|---|
| Official installer | Beginners who want a quick setup | Download the .pkg file from Node.js |
| Homebrew | Developers already using Terminal | brew install node |
| NVM | Projects that need different Node.js versions | nvm install --lts |
If you are just getting started, use the official LTS installer because it is the simplest and requires no extra configuration.
Method 1: Official Installer
- Open the official Node.js download page at
https://nodejs.org/en/download. - Choose the LTS (Long Term Support) version.
- Download the macOS Installer file with the
.pkgextension. - Open the downloaded file from your Downloads folder.
- Follow the installation wizard: click Continue, accept the license, select the installation location, then click Install.
- Enter your Mac password if prompted.
- Wait for the installation to finish, then click Close.
Verify the Installation
Open Terminal using Spotlight: press Command + Space, type Terminal, and press Enter.
Run these commands:
node -v
npm -v
If installation was successful, Terminal will display version numbers, for example:
v22.11.0
10.9.0
The command node -v checks the Node.js version, while npm -v checks the npm version.
Method 2: Homebrew
Homebrew makes it easy to install and update developer tools on macOS.
If Homebrew is not installed yet, install it using the command from its official website:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then install Node.js:
brew install node
Verify the installation:
node -v
npm -v
The command brew install node is a commonly recommended way to install Node.js on macOS.
Method 3: NVM for Multiple Versions
Use NVM (Node Version Manager) if you work on multiple projects that require different Node.js versions.
Install NVM:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash
Close and reopen Terminal, then run:
nvm install --lts
nvm use --lts
Verify the installation:
node -v
npm -v
NVM lets you switch Node.js versions per project—for example, Node 18 for an older project and Node 22 for a newer one.[nodejs]
Run Your First Node.js Program
Create a project folder and a simple JavaScript file:
mkdir learn-node
cd learn-node
nano app.js
Add this code:
console.log("Hello, Node.js on macOS!");
Save the file, then run:
node app.js
Terminal should display:
Hello, Node.js on macOS!
Troubleshooting
command not found: node— Close and reopen Terminal, or restart your Mac after installation.- Old Node.js version — Run
brew upgrade nodeif installed with Homebrew, ornvm install --ltsif using NVM. - Permission denied during installation — Enter your Mac administrator password when prompted.
- Need different versions across projects — Use NVM instead of installing multiple Node.js versions manually.
Once Node.js and npm are working, you can start a project with npm init -y, install packages with npm install <package-name>, and run scripts with node filename.js.




Comments
Join the discussion. Sign in with GitHub to leave a comment.