Skip to main content

Node.js Installation Guide

Node.js is a JavaScript runtime built on Chrome's V8 engine. This guide covers installation on Windows 11, macOS, and Linux with multiple version management options.

Trademark Notice

Node.js® and the Node.js logo are trademarks of OpenJS Foundation. All trademarks and logos are used for representation purposes only. No prior copyright or trademark authorization has been obtained. This documentation is for educational purposes only.

Version Management Tools

ToolBest ForPlatform Support
nvmVersion switching, developmentLinux, macOS, Windows (WSL)
nvm-windowsWindows nativeWindows
fnmFast, modern alternativeAll platforms
Official InstallerSimple, single versionAll platforms

Choosing a Version

  • LTS (Long Term Support): Recommended for production (v20.x)
  • Current: Latest features (v21.x)
  • Check versions: nodejs.org

Windows 11 Installation

Method 1: Official Installer (Easiest)

# Download from https://nodejs.org/
# Choose LTS version (recommended)

# Or using winget
winget install OpenJS.NodeJS.LTS

# Or using Chocolatey
choco install nodejs-lts

# Verify installation
node --version
npm --version
# Download nvm-windows installer
# Visit: https://github.com/coreybutler/nvm-windows/releases
# Download nvm-setup.exe

# After installation, restart PowerShell

# List available versions
nvm list available

# Install specific version
nvm install 20.10.0
nvm install 18.19.0

# Use specific version
nvm use 20.10.0

# List installed versions
nvm list

# Set default version
nvm alias default 20.10.0

# Verify
node --version
npm --version

Method 3: fnm (Fast Node Manager)

# Using winget
winget install Schniz.fnm

# Or using Chocolatey
choco install fnm

# Add to PowerShell profile
fnm env --use-on-cd | Out-String | Invoke-Expression

# Install Node.js
fnm install 20
fnm use 20

# Verify
node --version

Post-Installation (Windows)

# Set npm global directory (avoid permission issues)
mkdir "$env:APPDATA\npm"
npm config set prefix "$env:APPDATA\npm"

# Add to PATH (if not already)
# System Properties → Environment Variables → Path
# Add: %APPDATA%\npm

# Verify npm
npm --version

# Update npm
npm install -g npm@latest

macOS Installation

# Install Node.js LTS
brew install node@20

# Or install latest
brew install node

# Link if needed
brew link node@20

# Verify
node --version
npm --version

Method 2: Official Installer

# Download from https://nodejs.org/
# Choose .pkg for macOS
# Run installer and follow prompts

# Verify
node --version
npm --version

Method 3: nvm (Best for Multiple Versions)

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

# Or using Homebrew
brew install nvm

# Add to shell profile (~/.zshrc or ~/.bash_profile)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

# Reload shell
source ~/.zshrc

# Install Node.js
nvm install 20
nvm install 18
nvm install --lts

# Use specific version
nvm use 20

# Set default version
nvm alias default 20

# List installed versions
nvm ls

# Verify
node --version
npm --version

Method 4: fnm (Fast Alternative)

# Install fnm
brew install fnm

# Add to shell (~/.zshrc or ~/.bash_profile)
eval "$(fnm env --use-on-cd)"

# Install Node.js
fnm install 20
fnm use 20

# Set default
fnm default 20

# Verify
node --version

Linux Installation

Method 1: Package Manager (Ubuntu/Debian)

# Using NodeSource repository (Recommended)
# For Node.js 20.x LTS
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs

# Verify
node --version
npm --version

# Install build tools (optional, for native modules)
sudo apt-get install -y build-essential

Method 2: Package Manager (RHEL/CentOS/Fedora)

# For Node.js 20.x LTS
curl -fsSL https://rpm.nodesource.com/setup_20.x | sudo bash -
sudo dnf install -y nodejs

# Or for Fedora
sudo dnf install -y nodejs npm

# Verify
node --version
npm --version

Method 3: Package Manager (Arch Linux)

# Install Node.js
sudo pacman -S nodejs npm

# Verify
node --version
npm --version

Method 4: nvm (Best for Development)

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

# Or using wget
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

# Add to shell profile (~/.bashrc, ~/.zshrc, etc.)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"

# Reload shell
source ~/.bashrc

# Install Node.js
nvm install 20
nvm install 18
nvm install --lts

# Use specific version
nvm use 20

# Set default
nvm alias default 20

# List versions
nvm ls
nvm ls-remote # Show all available versions

# Verify
node --version
npm --version

Method 5: fnm (Modern Alternative)

# Install fnm
curl -fsSL https://fnm.vercel.app/install | bash

# Or using cargo (Rust)
cargo install fnm

# Add to shell (~/.bashrc or ~/.zshrc)
eval "$(fnm env --use-on-cd)"

# Install Node.js
fnm install 20
fnm use 20
fnm default 20

# Verify
node --version

Method 6: Binary Archive (Manual)

# Download Node.js binary
wget https://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.xz

# Extract
tar -xJf node-v20.10.0-linux-x64.tar.xz

# Move to /usr/local
sudo mv node-v20.10.0-linux-x64 /usr/local/node

# Add to PATH (~/.bashrc)
export PATH=/usr/local/node/bin:$PATH

# Reload
source ~/.bashrc

# Verify
node --version
npm --version

npm Configuration

Global Package Installation

# Check npm global directory
npm config get prefix

# Set custom global directory (avoid permission issues)
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'

# Add to PATH (~/.bashrc, ~/.zshrc, or PowerShell profile)
export PATH=~/.npm-global/bin:$PATH

# Reload shell
source ~/.bashrc

Update npm

# Update to latest npm
npm install -g npm@latest

# Check version
npm --version

Configure npm Registry

# Use default registry
npm config set registry https://registry.npmjs.org/

# Or use mirror (faster in some regions)
npm config set registry https://registry.npmmirror.com

# Check current registry
npm config get registry

Yarn Installation (Alternative Package Manager)

Windows

# Using npm
npm install -g yarn

# Or using Chocolatey
choco install yarn

# Verify
yarn --version

macOS

# Using Homebrew
brew install yarn

# Or using npm
npm install -g yarn

# Verify
yarn --version

Linux

# Using npm
npm install -g yarn

# Or using package manager (Debian/Ubuntu)
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install yarn

# Verify
yarn --version

pnpm Installation (Modern Package Manager)

# Using npm
npm install -g pnpm

# Or using curl (Unix)
curl -fsSL https://get.pnpm.io/install.sh | sh -

# Or using PowerShell (Windows)
iwr https://get.pnpm.io/install.ps1 -useb | iex

# Or using Homebrew (macOS)
brew install pnpm

# Verify
pnpm --version

Verification & Testing

Check Installation

# Check Node.js version
node --version
node -v

# Check npm version
npm --version
npm -v

# Check installation paths
which node
which npm

# Node.js REPL (interactive shell)
node
> console.log('Hello from Node.js!')
> .exit

# Run JavaScript file
echo "console.log('Hello World')" > test.js
node test.js

Test npm Package Installation

# Create test directory
mkdir test-node-app
cd test-node-app

# Initialize package.json
npm init -y

# Install a package
npm install lodash

# Create test script
cat > index.js << 'EOF'
const _ = require('lodash');
const numbers = [1, 2, 3, 4, 5];
console.log(_.sum(numbers));
EOF

# Run script
node index.js

# Clean up
cd ..
rm -rf test-node-app

Essential npm Commands

# Initialize project
npm init
npm init -y # Skip prompts

# Install dependencies
npm install # Install all from package.json
npm install <package> # Install specific package
npm install <package> --save-dev # Install as dev dependency
npm install -g <package> # Install globally

# Update packages
npm update # Update all packages
npm update <package> # Update specific package
npm outdated # Check for outdated packages

# Remove packages
npm uninstall <package>
npm uninstall -g <package>

# Run scripts (from package.json)
npm run <script>
npm start
npm test
npm run build

# List packages
npm list # Local packages
npm list -g --depth=0 # Global packages

# Check package info
npm info <package>
npm view <package> versions

# Clean cache
npm cache clean --force

# Audit security
npm audit
npm audit fix

nvm Commands Reference

# Install versions
nvm install 20 # Install Node.js 20
nvm install --lts # Install latest LTS
nvm install node # Install latest version

# Use versions
nvm use 20 # Switch to version 20
nvm use default # Use default version

# List versions
nvm ls # List installed versions
nvm ls-remote # List available versions
nvm ls-remote --lts # List LTS versions

# Set default
nvm alias default 20 # Set default version

# Uninstall version
nvm uninstall 18 # Remove version 18

# Run with specific version
nvm exec 20 node app.js # Run with Node.js 20
nvm run 20 app.js # Alternative syntax

# Get current version
nvm current

# Which version
nvm which 20 # Path to Node.js 20

Common Issues & Solutions

Issue: Permission Denied (npm install)

Linux/macOS:

# Fix npm permissions
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
source ~/.bashrc

Windows:

# Run PowerShell as Administrator or use nvm-windows

Issue: Command Not Found

# Check if Node.js is in PATH
echo $PATH # Unix
echo $env:PATH # PowerShell

# Add Node.js to PATH (example for Linux)
export PATH=$PATH:/usr/local/bin

Issue: EACCES Errors

# Change ownership of npm directories
sudo chown -R $USER:$USER ~/.npm
sudo chown -R $USER:$USER ~/.config

Issue: Multiple Node Versions Conflicting

# Use nvm to manage versions
nvm use 20
nvm alias default 20

# Check which node
which node
node --version

Issue: npm Behind Corporate Proxy

# Set proxy
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080

# Or use .npmrc file
echo "proxy=http://proxy.company.com:8080" >> ~/.npmrc
echo "https-proxy=http://proxy.company.com:8080" >> ~/.npmrc

Best Practices

Use LTS version for production
Use version manager (nvm/fnm) for development
Keep npm updated regularly
Use package-lock.json for consistent installs
Audit packages for security vulnerabilities
Use .nvmrc file for project-specific versions
Clean npm cache periodically
Use npm ci in CI/CD pipelines

.nvmrc File

# Create .nvmrc in project root
echo "20.10.0" > .nvmrc

# Use version from .nvmrc
nvm use

# Install version from .nvmrc
nvm install

Development Tools

Essential Global Packages

# TypeScript
npm install -g typescript

# Nodemon (auto-restart)
npm install -g nodemon

# PM2 (process manager)
npm install -g pm2

# ESLint (linting)
npm install -g eslint

# Create React App
npm install -g create-react-app

# Vue CLI
npm install -g @vue/cli

# Angular CLI
npm install -g @angular/cli

Next Steps

Node.js Installed Successfully!

Continue learning:

Additional Resources