Node.js Installation & Setup Guide

Complete step-by-step guide to install and configure Node.js on your computer. Learn how to set up Node.js on Windows, macOS, and Linux with best practices.

Introduction

Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It allows you to run JavaScript on the server side and build scalable network applications.

LTS vs Current

Node.js releases come in two versions:

  • LTS (Long Term Support): Recommended for production. Stable and receives updates for 30 months.
  • Current: Latest features but may have breaking changes. Good for experimentation.

Recommendation: Install the LTS version for production and learning.

Prerequisites

Before installing Node.js, ensure you have:

Basic understanding of command line interface (Terminal/Command Prompt)

Administrator/sudo access on your system

Stable internet connection for downloads

Windows Installation

Follow these steps to install Node.js on Windows:

Step 1: Download Node.js

  1. Visit nodejs.org
  2. Download the Windows Installer (.msi) for the LTS version
  3. Choose the 64-bit version for modern systems

Step 2: Run the Installer

  1. Double-click the downloaded .msi file
  2. Click "Next" on the welcome screen
  3. Accept the license agreement
  4. Choose the installation location (default is fine)
  5. Select "Complete" installation to install npm as well
  6. Check "Automatically install necessary tools" if prompted
  7. Click "Install" and wait for completion
  8. Click "Finish"

Step 3: Verify Installation

Open Command Prompt or PowerShell and run:

bash
node --version
npm --version

You should see version numbers like v20.10.0 and 10.2.3

macOS Installation

There are two recommended ways to install Node.js on macOS:

Option 1: Using Homebrew (Recommended)

If you have Homebrew installed, this is the easiest method:

bash
# Install Homebrew if you don't have it
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Node.js
brew install node
# Verify installation
node --version
npm --version

Option 2: Official Installer

  1. Visit nodejs.org
  2. Download the macOS Installer (.pkg) for the LTS version
  3. Double-click the .pkg file to run the installer
  4. Follow the installation wizard
  5. Enter your password when prompted
  6. Click "Install" and wait for completion
Linux Installation

Installation varies by Linux distribution. Here are instructions for popular distros:

Ubuntu/Debian

Using NodeSource repository (recommended for latest version):

bash
# Download and import NodeSource GPG key
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
# Install Node.js
sudo apt-get install -y nodejs
# Verify installation
node --version
npm --version

Fedora/CentOS/RHEL

bash
# Download NodeSource setup script
curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
# Install Node.js
sudo dnf install -y nodejs
# Verify installation
node --version
npm --version

Arch Linux

bash
# Install Node.js
sudo pacman -S nodejs npm
# Verify installation
node --version
npm --version
Using NVM (Node Version Manager)

NVM allows you to install and switch between multiple Node.js versions easily. This is eFspecially useful when working on different projects.

Pro Tip

If you plan to work on multiple projects or need to test across different Node.js versions, start with NVM instead of a direct installation.

Install NVM (macOS/Linux)

bash
# Download and install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Reload shell configuration
source ~/.bashrc # or ~/.zshrc for zsh
# Verify NVM installation
nvm --version

Install NVM (Windows)

Use nvm-windows:

  1. Download nvm-setup.zip from the releases page
  2. Extract and run nvm-setup.exe
  3. Follow the installation wizard
  4. Open a new Command Prompt

Using NVM

bash
# Install latest LTS version
nvm install --lts
# Install a specific version
nvm install 20.10.0
# List installed versions
nvm list
# Switch to a specific version
nvm use 20.10.0
# Set default version
nvm alias default 20.10.0
# Verify current version
node --version
Verify Installation

After installation, verify that Node.js and npm are working correctly:

Check Versions

bash
node --version
npm --version

Expected output: version numbers like v20.10.0 and 10.2.3

Test Node.js

Create a simple test file:

javascript
// test.js
console.log('Node.js is working!');
console.log('Node version:', process.version);

Run the file:

bash
node test.js

Test npm

bash
# Create a new directory
mkdir test-project
cd test-project
# Initialize a new npm project
npm init -y
# You should see a package.json file created

Success!

Your Node.js environment is ready! You can now proceed to learn Node.js fundamentals and start building applications.

Built for learning — keep experimenting!