Installation Guide

Everything you need to get Node.js® up and running on macOS.

Step-by-Step Installation

Follow these phases to install Node.js on macOS.

Phase 1

Open Terminal

If Terminal is not already open, follow these steps:

  1. Press Command (⌘) + Space to open Spotlight Search.
  2. Type Terminal.
  3. Press Return to launch it.

Keep the Terminal window open for the next phases.

Phase 2

Install Node.js via Homebrew

If you don't have Homebrew installed yet, install it first:

Terminal
echo 

Then install Node.js:

  1. Copy the installation command below.
  2. Paste it into your Terminal window.
  3. Press Return to execute it.
  4. Enter your administrator password if prompted.

Password Tip — When entering your password in Terminal, no characters or asterisks will appear on the screen. This is standard macOS behavior. Just type your password normally and press Return.

Phase 3

Verify Installation

Run the following commands in Terminal to confirm Node.js and npm are installed correctly:

  1. Type node --version and press Return.
  2. Type npm --version and press Return.
Terminal
node --version
npm --version

You should see version numbers printed for both commands, for example:

Output
v24.14.1
10.9.2
Phase 4

Test with Hello World

Create a simple test file to make sure everything works:

  1. Create a new file called hello.mjs with the code below.
  2. Run node hello.mjs in Terminal.
  3. Open http://127.0.0.1:3000 in your browser.
hello.mjs
import { createServer } from 'node:http';

const server = createServer((req, res) => {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello World!\n');
});

server.listen(3000, '127.0.0.1', () => {
  console.log('Listening on http://127.0.0.1:3000');
});
Terminal
node hello.mjs

You should see "Hello World!" displayed in your browser.

Verify Installation

Make sure your environment is set up correctly by checking these commands.

Node.js Version

Terminal
node --version

npm Version

Terminal
npm --version

npx Version

Terminal
npx --version

Installation Path

Terminal
which node

Version Management with NVM

Use Node Version Manager to install and switch between multiple Node.js versions.

Install NVM

Terminal

Restart your terminal, then verify:

Terminal
nvm --version

Common NVM Commands

Terminal
# Install the latest LTS version
nvm install --lts

# Install a specific major version
nvm install 24

# Switch to a specific version
nvm use 24

# List installed versions
nvm ls

# Set default version
nvm alias default 24

Troubleshooting

Common issues and how to resolve them.

"node: command not found"

This usually means Node.js is not in your system PATH. Add the following to your shell profile (~/.zshrc or ~/.bashrc):

Terminal
export PATH="/usr/local/bin:$PATH"

Then reload your shell with source ~/.zshrc.

Permission errors (EACCES)

Avoid using sudo with npm. Instead, change npm's default directory:

Terminal
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.zshrc
source ~/.zshrc

Or better yet, use NVM which handles permissions automatically.

npm install hangs or is very slow

Try clearing the npm cache and setting a different registry:

Terminal
npm cache clean --force
npm config set registry https://registry.npmjs.org/
Multiple Node.js versions conflict

Use NVM (Node Version Manager) to manage multiple versions. It allows you to install and switch between different Node.js versions without conflicts.