Master Code
On The Go

Learn. Practice. Build.

How-To Guide

How to Install Node.js and npm

Node.js lets you run JavaScript outside the browser. Here's how to install it on any operating system in under 8 minutes.

🟢 What is Node.js?

Node.js is a JavaScript runtime that lets you run JS on your computer instead of in a browser. It's used for:

When you install Node.js, you also get npm — the Node Package Manager — which gives you access to over 2 million open-source packages.

📋 What You'll Need

✅ Node.js is free and open source. No signup, no license, no trial.

❓ Which Version Should You Install?

Node.js offers two versions on its download page:

LTS (Long-Term Support) ✅

  • Stable, tested, supported for years
  • Recommended for almost everyone
  • Best for production and learning

Current

  • Latest features
  • ⚠️ May have bugs
  • Only for advanced users testing new features

💡 Rule of thumb: Always choose LTS unless you have a specific reason to use Current.

1

Download Node.js

Go to the official website:

👉 nodejs.org

The site detects your OS and shows two big buttons. Click the one that says LTS (Long-Term Support).

Direct download options:

  • Windows: "Windows Installer (.msi)" — 64-bit is standard
  • Mac: "macOS Installer (.pkg)" — works on Intel and Apple Silicon
  • Linux: use your package manager or nvm (see below)
2

Run the Installer

Windows:

  1. Open the downloaded .msi file
  2. Click "Next" through the welcome screen
  3. Accept the license agreement
  4. Keep the default install location (C:\Program Files\nodejs)
  5. On the "Tools for Native Modules" screen, leave it unchecked for now (you can enable it later if needed)
  6. Click "Install" and wait for completion
  7. Click "Finish"

Mac:

  1. Open the downloaded .pkg file
  2. Click "Continue" through the installer screens
  3. Accept the license
  4. Click "Install" and enter your Mac password
  5. Wait for the installer to finish

Linux (Ubuntu/Debian):

The system package is often outdated. The recommended way is nvm (see Step 5), or you can use NodeSource:

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

For Fedora/RHEL:

sudo dnf install nodejs npm
3

Verify the Installation

Open a fresh terminal window:

  • Windows: press Win + R, type cmd, hit Enter
  • Mac: press Cmd + Space, type "Terminal", hit Enter
  • Linux: press Ctrl + Alt + T

Check Node.js:

node --version

You should see something like:

v20.11.0

Check npm:

npm --version

You should see something like:

10.2.4

If both commands return version numbers, you're good to go.

4

Test with Your First Script

Create a file called hello.js anywhere. Open it in VS Code (or any text editor) and paste:

console.log("Hello from Node!");

// Bonus: check the Node version programmatically
console.log("Node version:", process.version);

// Bonus: simple math to prove it's running JS
const numbers = [1, 2, 3, 4, 5];
const sum = numbers.reduce((a, b) => a + b, 0);
console.log("Sum of 1-5:", sum);

Save the file. In your terminal, navigate to the folder and run:

node hello.js

You should see:

Hello from Node!
Node version: v20.11.0
Sum of 1-5: 15

🎉 Node.js is installed and working!

5

Bonus: Install nvm (Recommended)

Real projects often need different Node.js versions. Node Version Manager (nvm) lets you switch between them per project.

Mac / Linux:

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

Then restart your terminal and verify:

nvm --version

Install a Node version:

nvm install --lts
nvm use --lts

Windows:

Use nvm-windows from the official GitHub:

👉 github.com/coreybutler/nvm-windows/releases

;

💡 When to use nvm: When you work on multiple projects that require different Node versions (e.g., one needs Node 18, another needs Node 20). For your very first install, plain Node.js is fine.

📦 Bonus: Your First npm Commands

npm is how you install libraries. Here are the four commands you'll use constantly:

Initialize a project

mkdir my-project
cd my-project
npm init -y

Creates a package.json file that describes your project.

Install a package

npm install express

Adds Express to your project's dependencies.

Install a dev-only package

npm install --save-dev nodemon

For tools used only during development.

Run a script from package.json

npm run start

Runs the command defined under "scripts" in package.json.

🔧 Common Errors (and Fixes)

❌ 'node' is not recognized as an internal or external command

Node isn't on your PATH. Fixes:

  1. Close and reopen your terminal (PATH changes only apply to new sessions)
  2. Reboot your computer if that doesn't work
  3. On Windows, reinstall Node.js and ensure it uses the default install location

❌ 'npm' is not recognized (but 'node' works)

Rare, but happens when PATH is partially configured. On Windows, check that C:\Program Files\nodejs is in your system PATH.

❌ EACCES permission errors when running npm install

Don't use sudo npm install -g. It can break system directories. Better options:

  1. Install nvm and use it (see Step 5)
  2. Configure npm to use a user-level prefix
  3. Use npm install --user for global installs

❌ "npm ERR! code EINTEGRITY" during install

Corrupted npm cache. Fix:

npm cache clean --force
npm install

❌ Multiple Node versions causing errors

Check which version is active:

which node    # Mac/Linux
where node    # Windows

If it points to an unexpected location, uninstall other installations or use nvm to control versions.

❌ "Unsupported engine" warnings on npm install

A package requires a newer Node version than you have. Check what version you need, then upgrade with nvm:

nvm install 20
nvm use 20

🎯 What's Next?

Node.js is installed. Now learn JavaScript properly — that's the language Node runs.

← All How-To Guides