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:
- Building web servers and APIs
- Running build tools (Vite, Webpack, etc.)
- Command-line tools and automation scripts
- Real-time apps (chat, collaboration tools)
- Full-stack JavaScript development
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
- A computer running Windows 10/11, macOS 11+, or Linux
- An internet connection
- About 100 MB of free disk space
- 5–8 minutes of your time
✅ 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.
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)
Run the Installer
Windows:
- Open the downloaded
.msifile - Click "Next" through the welcome screen
- Accept the license agreement
- Keep the default install location (
C:\Program Files\nodejs) - On the "Tools for Native Modules" screen, leave it unchecked for now (you can enable it later if needed)
- Click "Install" and wait for completion
- Click "Finish"
Mac:
- Open the downloaded
.pkgfile - Click "Continue" through the installer screens
- Accept the license
- Click "Install" and enter your Mac password
- 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
Verify the Installation
Open a fresh terminal window:
- Windows: press
Win + R, typecmd, 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.
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!
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:
- Close and reopen your terminal (PATH changes only apply to new sessions)
- Reboot your computer if that doesn't work
- 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:
- Install nvm and use it (see Step 5)
- Configure npm to use a user-level prefix
- Use
npm install --userfor 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.