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.
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.
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
Follow these steps to install Node.js on Windows:
Step 1: Download Node.js
- Visit nodejs.org
- Download the Windows Installer (.msi) for the LTS version
- Choose the 64-bit version for modern systems
Step 2: Run the Installer
- Double-click the downloaded .msi file
- Click "Next" on the welcome screen
- Accept the license agreement
- Choose the installation location (default is fine)
- Select "Complete" installation to install npm as well
- Check "Automatically install necessary tools" if prompted
- Click "Install" and wait for completion
- Click "Finish"
Step 3: Verify Installation
Open Command Prompt or PowerShell and run:
node --versionnpm --version
You should see version numbers like v20.10.0 and 10.2.3
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:
# Install Homebrew if you don't have it/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"# Install Node.jsbrew install node# Verify installationnode --versionnpm --version
Option 2: Official Installer
- Visit nodejs.org
- Download the macOS Installer (.pkg) for the LTS version
- Double-click the .pkg file to run the installer
- Follow the installation wizard
- Enter your password when prompted
- Click "Install" and wait for completion
Installation varies by Linux distribution. Here are instructions for popular distros:
Ubuntu/Debian
Using NodeSource repository (recommended for latest version):
# Download and import NodeSource GPG keycurl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -# Install Node.jssudo apt-get install -y nodejs# Verify installationnode --versionnpm --version
Fedora/CentOS/RHEL
# Download NodeSource setup scriptcurl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -# Install Node.jssudo dnf install -y nodejs# Verify installationnode --versionnpm --version
Arch Linux
# Install Node.jssudo pacman -S nodejs npm# Verify installationnode --versionnpm --version
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)
# Download and install NVMcurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash# Reload shell configurationsource ~/.bashrc # or ~/.zshrc for zsh# Verify NVM installationnvm --version
Install NVM (Windows)
Use nvm-windows:
- Download nvm-setup.zip from the releases page
- Extract and run nvm-setup.exe
- Follow the installation wizard
- Open a new Command Prompt
Using NVM
# Install latest LTS versionnvm install --lts# Install a specific versionnvm install 20.10.0# List installed versionsnvm list# Switch to a specific versionnvm use 20.10.0# Set default versionnvm alias default 20.10.0# Verify current versionnode --version
After installation, verify that Node.js and npm are working correctly:
Check Versions
node --versionnpm --version
Expected output: version numbers like v20.10.0 and 10.2.3
Test Node.js
Create a simple test file:
// test.jsconsole.log('Node.js is working!');console.log('Node version:', process.version);
Run the file:
node test.js
Test npm
# Create a new directorymkdir test-projectcd test-project# Initialize a new npm projectnpm 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.