Node.jsBackendFull-Stack

Installing Node.js and npm: Your Complete Setup Guide

TT
TopicTrick Team
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:

  1. Permission errors — The system-level install requires sudo for global npm packages, which causes frequent headaches.
  2. 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:

bash
nvm use 20    # switch to Node 20
nvm use 18    # switch to Node 18

Every 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:

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

This 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

bash
source ~/.zshrc
# or if you use bash:
source ~/.bashrc

Verify nvm is available:

bash
nvm --version
# Expected output: 0.39.7

Step 3: Install Node.js LTS

bash
nvm install --lts

This 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

bash
node --version
# v20.x.x

npm --version
# 10.x.x

Both 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

bash
sudo apt-get update
sudo apt-get install -y curl build-essential

Step 2: Install nvm

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

Step 3: Reload and verify

bash
source ~/.bashrc
nvm --version

Step 4: Install Node.js LTS

bash
nvm install --lts
node --version
npm --version

Installing 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

powershell
nvm install lts
nvm use lts

Step 5: Verify

powershell
node --version
npm --version

Windows 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:

TrackDescriptionRecommended For
LTS (Long-Term Support)Supported for 30 months. Even-numbered major versions (18, 20, 22).Production apps, learning, team projects
CurrentLatest 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.

bash
# 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 20

Understanding 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:

bash
npm install express          # install in current project
npm install -g nodemon       # install globally

2. Script runner — run commands defined in package.json:

bash
npm run dev
npm run build
npm test

3. Package publisher — publish your own packages to the npm registry (covered in a later module).

Useful npm Commands

bash
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 vulnerabilities

Setting 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):

ExtensionPurpose
ESLintCatches code errors and enforces style rules
PrettierAuto-formats your code on save
REST ClientTest API endpoints directly inside VS Code
GitLensSupercharged Git history and blame
Thunder ClientLightweight Postman alternative for API testing
Node.js Extension PackDebugging, snippets, and IntelliSense

Workspace Settings

Create a .vscode/settings.json file in your project root to enable format-on-save:

json
{
  "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.

bash
mkdir node-test && cd node-test
npm init -y

Create a file called index.js:

javascript
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:

bash
node index.js

You should see output like:

text
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.

bash
npm install -g nodemon

Verify:

bash
nodemon --version
# 3.x.x

You will use nodemon throughout this course instead of running node index.js manually.


Common Setup Issues and Fixes

ProblemCauseFix
nvm: command not foundShell profile not reloadedRun source ~/.zshrc or open a new terminal
node: command not found after nvm installnvm is loaded but no version selectedRun nvm use --lts
EACCES: permission denied on npm installOld system Node.js install conflictUninstall system Node, use only nvm-managed version
npm install hangsNetwork/proxy issueTry npm install --prefer-offline or check your proxy settings
Wrong Node version after restartNo default setRun 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