Installing Node.js and npm: Your Complete Setup Guide

Installing Node.js and npm: Your Complete Setup Guide
Before you write a single line of Node.js code, you need a clean, professional development environment. This guide walks you through installing Node.js and npm the right way — using nvm (Node Version Manager) — on macOS, Linux, and Windows. You will also verify your setup, understand the difference between LTS and Current releases, and configure your editor for Node.js development.
This is Module 2 of the Node.js Full‑Stack Developer course. By the end you will have Node.js running on your machine and be ready to write your first program in Module 3.
Why Use nvm Instead of Downloading from nodejs.org?
Most tutorials tell you to download the installer from nodejs.org. That works, but it creates two problems:
- Permission errors — The system-level install requires
sudofor global npm packages, which causes frequent headaches. - Version lock — Real projects have specific Node.js version requirements. Without a version manager, switching between them is painful.
nvm (Node Version Manager) solves both. It installs Node.js into your home directory (no sudo needed) and lets you switch versions with a single command:
nvm use 20 # switch to Node 20
nvm use 18 # switch to Node 18Every professional Node.js developer uses nvm (or its Windows equivalent, nvm-windows). Use it from day one.
Installing Node.js on macOS
Step 1: Install nvm
Open your terminal and run the official nvm install script:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bashThis downloads and runs the installer, which adds nvm to your shell profile (~/.zshrc on macOS with Zsh, or ~/.bashrc for Bash).
Step 2: Reload Your Shell
source ~/.zshrc
# or if you use bash:
source ~/.bashrcVerify nvm is available:
nvm --version
# Expected output: 0.39.7Step 3: Install Node.js LTS
nvm install --ltsThis installs the latest Long-Term Support release (Node 20.x as of 2026). After installation, nvm automatically switches to it.
Step 4: Verify the Installation
node --version
# v20.x.x
npm --version
# 10.x.xBoth commands should return version numbers. If you see command not found, run source ~/.zshrc again and retry.
Installing Node.js on Linux (Ubuntu / Debian)
The process is identical to macOS:
Step 1: Install build essentials
sudo apt-get update
sudo apt-get install -y curl build-essentialStep 2: Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bashStep 3: Reload and verify
source ~/.bashrc
nvm --versionStep 4: Install Node.js LTS
nvm install --lts
node --version
npm --versionInstalling Node.js on Windows
nvm does not support Windows natively. Instead, use nvm-windows — a separate, community-maintained tool that works the same way.
Step 1: Download nvm-windows
Go to the nvm-windows releases page and download nvm-setup.exe from the latest release.
Step 2: Run the installer
Run nvm-setup.exe and follow the prompts. Accept the default installation paths.
Important: If you have an existing Node.js installation, nvm-windows will offer to control it. Say yes.
Step 3: Open a new terminal as Administrator
Open PowerShell or Command Prompt as Administrator (right-click → "Run as administrator").
Step 4: Install Node.js LTS
nvm install lts
nvm use ltsStep 5: Verify
node --version
npm --versionWindows Subsystem for Linux (WSL2) — Recommended
If you are doing serious Node.js development on Windows, consider using WSL2 (Windows Subsystem for Linux). It gives you a full Linux environment and lets you use the standard nvm install. Most professional Windows-based Node.js developers work inside WSL2.
LTS vs Current: Which Version Should You Install?
Node.js releases on a predictable schedule with two tracks:
| Track | Description | Recommended For |
|---|---|---|
| LTS (Long-Term Support) | Supported for 30 months. Even-numbered major versions (18, 20, 22). | Production apps, learning, team projects |
| Current | Latest features, shorter support window. Odd-numbered majors (19, 21). | Experimentation, cutting-edge feature testing |
Install LTS. For this course, use Node 20 LTS or the latest LTS at the time you read this.
# See all available LTS versions
nvm ls-remote --lts
# Install a specific version
nvm install 20.14.0
# List installed versions
nvm ls
# Switch version for this session
nvm use 20
# Set the default for all new terminals
nvm alias default 20Understanding npm: Node Package Manager
When you installed Node.js via nvm, npm came bundled with it. npm has three roles:
1. Package installer — download and install libraries from the npm registry:
npm install express # install in current project
npm install -g nodemon # install globally2. Script runner — run commands defined in package.json:
npm run dev
npm run build
npm test3. Package publisher — publish your own packages to the npm registry (covered in a later module).
Useful npm Commands
npm init -y # create a package.json with defaults
npm install <package> # install and add to dependencies
npm install -D <package> # install as devDependency
npm uninstall <package> # remove a package
npm update # update all packages
npm list # show installed packages
npm outdated # show packages with newer versions available
npm audit # check for known security vulnerabilitiesSetting Up Your Editor: VS Code for Node.js
Visual Studio Code is the most popular editor for Node.js development. If you do not have it, download it from code.visualstudio.com.
Recommended Extensions
Install these from the VS Code Extensions panel (Ctrl+Shift+X):
| Extension | Purpose |
|---|---|
| ESLint | Catches code errors and enforces style rules |
| Prettier | Auto-formats your code on save |
| REST Client | Test API endpoints directly inside VS Code |
| GitLens | Supercharged Git history and blame |
| Thunder Client | Lightweight Postman alternative for API testing |
| Node.js Extension Pack | Debugging, snippets, and IntelliSense |
Workspace Settings
Create a .vscode/settings.json file in your project root to enable format-on-save:
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.tabSize": 2,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}Your First Smoke Test
Let us make sure everything works end to end. Create a new folder, initialise a project, and run a quick script.
mkdir node-test && cd node-test
npm init -yCreate a file called index.js:
const os = require('os')
console.log('Node.js version:', process.version)
console.log('Platform:', os.platform())
console.log('CPU cores:', os.cpus().length)
console.log('Free memory:', Math.round(os.freemem() / 1024 / 1024), 'MB')
console.log('\n✅ Node.js is working correctly!')Run it:
node index.jsYou should see output like:
Node.js version: v20.14.0
Platform: darwin
CPU cores: 10
Free memory: 4821 MB
✅ Node.js is working correctly!If you see that output, your Node.js environment is ready.
Installing nodemon for Development
When building Node.js apps, you will constantly edit your code and restart the server. nodemon automates this — it watches your files and restarts Node.js automatically when anything changes.
npm install -g nodemonVerify:
nodemon --version
# 3.x.xYou will use nodemon throughout this course instead of running node index.js manually.
Common Setup Issues and Fixes
| Problem | Cause | Fix |
|---|---|---|
nvm: command not found | Shell profile not reloaded | Run source ~/.zshrc or open a new terminal |
node: command not found after nvm install | nvm is loaded but no version selected | Run nvm use --lts |
EACCES: permission denied on npm install | Old system Node.js install conflict | Uninstall system Node, use only nvm-managed version |
| npm install hangs | Network/proxy issue | Try npm install --prefer-offline or check your proxy settings |
| Wrong Node version after restart | No default set | Run nvm alias default <version> |
Node.js Full‑Stack Course — Module 2 of 32
You now have a professional Node.js development environment. Continue to Module 3 to write and understand your first Node.js program.
Summary
You now have a production-grade Node.js development environment set up with nvm. Here is what you configured:
- nvm installed for flexible version management (macOS/Linux/Windows)
- Node.js LTS installed and verified
- npm configured and ready for package management
- VS Code with the right extensions and settings
- nodemon installed for automatic server restarts during development
In Module 3: Your First Node.js Program → you will write your first Node.js script, understand how the runtime executes it, and explore the global objects available in every Node.js program.
Content powered by SearchFit.ai — for automated content at scale, visit https://searchfit.ai
