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.
Open Terminal
If Terminal is not already open, follow these steps:
- Press Command (⌘) + Space to open Spotlight Search.
- Type Terminal.
- Press Return to launch it.
Keep the Terminal window open for the next phases.
Install Node.js via Homebrew
If you don't have Homebrew installed yet, install it first:
echo
Then install Node.js:
- Copy the installation command below.
- Paste it into your Terminal window.
- Press Return to execute it.
- 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.
Verify Installation
Run the following commands in Terminal to confirm Node.js and npm are installed correctly:
- Type
node --versionand press Return. - Type
npm --versionand press Return.
node --version
npm --version
You should see version numbers printed for both commands, for example:
v24.14.1
10.9.2
Test with Hello World
Create a simple test file to make sure everything works:
- Create a new file called
hello.mjswith the code below. - Run
node hello.mjsin Terminal. - Open http://127.0.0.1:3000 in your browser.
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');
});
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
node --version
npm Version
npm --version
npx Version
npx --version
Installation Path
which node
Version Management with NVM
Use Node Version Manager to install and switch between multiple Node.js versions.
Install NVM
Restart your terminal, then verify:
nvm --version
Common NVM Commands
# 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):
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:
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:
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.