Node.js Installation Guide
Official Installation Methods
Node.js provides several official installation methods to suit different operating systems and user preferences. All official methods ensure you get the authentic, unmodified binaries directly from the Node.js project.
Download from Official Website
The most straightforward way to install Node.js is by downloading the appropriate installer from the official Node.js website.
Available Versions:
- LTS (Long-Term Support): Recommended for most users. Provides stability and long-term support.
- Current: Latest features with shorter support cycle. Suitable for development and testing.
Package Managers
macOS (Homebrew)
# Install Homebrew if not already installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Node.js LTS
brew install node@20
# Or install the latest Current version
brew install node
Linux (Various Distributions)
Ubuntu/Debian:
# Using NodeSource repository (recommended)
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
CentOS/RHEL/Fedora:
# Using NodeSource repository
curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
sudo yum install nodejs
# or for newer versions: sudo dnf install nodejs
Windows
- Download the Windows Installer (.msi) from the official website
- Run the installer and follow the setup wizard
- Node.js and npm will be automatically added to your PATH
Node Version Managers
For developers who need to work with multiple Node.js versions, version managers provide an excellent solution.
nvm (Node Version Manager) - macOS/Linux
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
# Install and use LTS version
nvm install --lts
nvm use --lts
# Install specific version
nvm install 20.14.0
nvm use 20.14.0
# List available versions
nvm list-remote
nvm-windows - Windows
- Download from nvm-windows GitHub releases
- Follow the installation instructions
- Use similar commands as Unix-based nvm
Verification
After installation, verify that Node.js and npm are properly installed:
# Check Node.js version
node --version
# Check npm version
npm --version
# Test basic functionality
node -e "console.log('Node.js is working!')"
Post-Installation Setup
Global npm Packages Location
By default, globally installed npm packages are placed in a system directory. To avoid permission issues, consider configuring npm to use a different directory:
# Create a directory for global packages
mkdir ~/.npm-global
# Configure npm to use the new directory
npm config set prefix '~/.npm-global'
# Add the directory to your PATH (add to ~/.bashrc or ~/.zshrc)
export PATH=~/.npm-global/bin:$PATH
Environment Variables
Common environment variables for Node.js development:
NODE_ENV: Set toproductionin production environmentsNODE_OPTIONS: Pass command-line options to Node.js processesNPM_CONFIG_*: Configure npm behavior through environment variables
Release Schedule Understanding
Node.js follows a predictable release schedule:
- Current releases: New major versions every 6 months
- LTS releases: Even-numbered versions become LTS after 6 months
- Active LTS: 18 months of active support
- Maintenance LTS: 12 months of maintenance support (total 30 months)
Choose LTS versions for production applications to ensure stability and long-term support.
Security Considerations
- Always download from official sources (nodejs.org or official package repositories)
- Verify downloaded binaries using provided SHASUMS when possible
- Keep Node.js updated to receive security patches
- Use LTS versions in production for guaranteed security updates
