MW

How-To · Tools

How to Install Node.js + npm on Windows, Mac, and Linux (2026) — Every Method

Node.js bundles npm with every install — pick the method that fits your OS and you're done in under 5 minutes. Here's how on Windows, macOS, and Linux.

Jan 24, 2025 6 min read Any platform beginner
Advertisement

Node.js and npm (Node Package Manager) are essential tools for modern JavaScript development. Whether you’re building React/Vue/Angular apps, running build tools like Webpack or Vite, or shipping WordPress blocks, you need Node.js + npm installed.

This guide covers every installation method for Windows, macOS, and Linux. By the end, your terminal should look like this:

Terminal — installed correctly
$ node --version
v20.10.0
$ npm --version
10.2.3

Understanding Node.js and npm

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 command-line tools.

npm (Node Package Manager) comes bundled with Node.js and is the default package manager for the JavaScript ecosystem. It allows you to:

  • Install and manage JavaScript packages
  • Share your own packages
  • Manage project dependencies
  • Run scripts and build tools

Key Points:

  • Installing Node.js automatically installs npm
  • npm version is tied to Node.js version
  • Both should be kept updated
  • Version managers allow multiple versions

Windows Installation

The easiest way to install Node.js on Windows:

  1. Visit nodejs.org
  2. Download the LTS (Long Term Support) version for Windows
  3. Run the installer (.msi file)
  4. Follow the installation wizard
  5. Check “Automatically install necessary tools” if prompted
  6. Restart your computer if required
  7. Verify installation: Open Command Prompt and run node —version

Installation Options:

  • LTS Version: Recommended for most users (stable, long-term support)
  • Current Version: Latest features, may be less stable

What Gets Installed:

  • Node.js runtime
  • npm package manager
  • Adds Node.js to system PATH
  • npm global folder configuration

Method 2: Using Chocolatey

If you have Chocolatey package manager installed:

choco install nodejs

Update:

choco upgrade nodejs

Windows Package Manager — built into Windows 10/11, no extra setup needed:

PowerShell — winget install
C:\> winget install OpenJS.NodeJS.LTS
Found Node.js LTS [OpenJS.NodeJS.LTS] Version 20.10.0 Downloading https://nodejs.org/dist/v20.10.0/node-v20.10.0-x64.msi Successfully installed
C:\> node --version
v20.10.0
C:\> npm --version
10.2.3

Method 4: Using Scoop

If you use Scoop package manager:

scoop install nodejs

macOS Installation

Method 1: Official Installer

The simplest method for macOS:

  1. Visit nodejs.org
  2. Download the macOS installer (.pkg file)
  3. Open the downloaded file
  4. Follow the installation wizard
  5. Verify: Open Terminal and run node --version

Homebrew is the most popular package manager for macOS. One command and you’re done:

Terminal — Homebrew install
$ brew install node
==> Pouring node--20.10.0.arm64_sonoma.bottle.tar.gz ==> Installed /opt/homebrew/Cellar/node/20.10.0 (2,193 files, 76.4MB)
$ node --version
v20.10.0
$ npm --version
10.2.3

Updating later is just as easy: brew upgrade node.

Benefits of Homebrew:

  • Easy updates
  • Manages dependencies automatically
  • Can install multiple versions

Method 3: Using MacPorts

If you use MacPorts:

sudo port install nodejs18

Method 4: Using nvm (Node Version Manager)

For managing multiple Node.js versions (useful when projects need different ones):

Terminal — install nvm + multiple Node versions
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
=> nvm source string already in /Users/mahesh/.zshrc => Close and reopen your terminal to start using nvm
$ nvm install --lts
Installing Node.js v20.10.0... Now using node v20.10.0 (npm v10.2.3)
$ nvm install 18
Now using node v18.19.0 (npm v10.2.3)
$ nvm use --lts
Now using node v20.10.0

Linux Installation

Ubuntu/Debian

Method 1: Using NodeSource Repository (Recommended)

The default Ubuntu/Debian repos ship outdated Node — use NodeSource for the actual LTS:

bash — NodeSource LTS on Ubuntu/Debian
$ curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
## Installing the NodeSource Node.js LTS repo...
$ sudo apt-get install -y nodejs
Setting up nodejs (20.10.0-1nodesource1)
$ node --version && npm --version
v20.10.0 10.2.3

Method 2: Using Default Repository

sudo apt update
sudo apt install nodejs npm

Note: Default repository may have older versions.

Fedora/RHEL/CentOS

Using NodeSource Repository:

curl -fsSL https://rpm.nodesource.com/setup_lts.x | sudo bash -
sudo yum install -y nodejs

Or using dnf:

sudo dnf install nodejs npm

Arch Linux

sudo pacman -S nodejs npm

openSUSE

sudo zypper install nodejs npm

Using Version Managers

Version managers allow you to install and switch between multiple Node.js versions, which is useful for:

  • Testing compatibility
  • Working on multiple projects
  • Following project requirements

nvm (Node Version Manager) - macOS/Linux

Installation:

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

Usage:

nvm install 18.17.0        # Install specific version
nvm install --lts          # Install latest LTS
nvm use 18.17.0           # Switch to version
nvm list                  # List installed versions
nvm alias default 18.17.0 # Set default version

nvm-windows (Windows)

Installation:

  1. Download from github.com/coreybutler/nvm-windows/releases
  2. Run the installer
  3. Restart Command Prompt

Usage:

nvm install 18.17.0
nvm use 18.17.0
nvm list

fnm (Fast Node Manager) - Cross-platform

Installation (macOS/Linux):

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

Installation (Windows):

winget install Schniz.fnm

Usage:

fnm install 18.17.0
fnm use 18.17.0
fnm list

Verify Installation

After installation, verify everything works:

Check Node.js Version

node --version
# or
node -v

Should display version number (e.g., v18.17.0).

Check npm Version

npm --version
# or
npm -v

Should display npm version (e.g., 9.6.7).

Test Installation

Create a test file test.js:

console.log('Node.js is working!');

Run it:

node test.js

Should output: Node.js is working!

Check Installation Paths

Node.js location:

which node        # macOS/Linux
where node        # Windows

npm location:

which npm         # macOS/Linux
where npm         # Windows

Check Global npm Configuration

npm config list
npm config get prefix

Updating Node.js and npm

Updating Node.js

Windows/macOS (Official Installer):

  1. Download latest installer from nodejs.org
  2. Run installer (it will update existing installation)
  3. Verify with node --version

Homebrew (macOS):

brew upgrade node

Linux (NodeSource):

curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

Using Version Managers:

nvm install --lts
nvm use --lts

Updating npm

npm can be updated independently:

npm install -g npm@latest

Check for updates:

npm outdated -g

Update to specific version:

npm install -g npm@9.6.7

Troubleshooting Common Issues

Issue: “node is not recognized”

Windows: Node.js not in PATH

  • Reinstall Node.js and check “Add to PATH” option
  • Manually add to PATH: C:\Program Files\nodejs\
  • Restart Command Prompt completely

macOS/Linux: Installation incomplete

  • Verify installation: which node
  • Check PATH: echo $PATH
  • Reinstall if necessary

Issue: npm Command Not Found

Solution:

  1. Verify Node.js is installed: node --version
  2. npm should come with Node.js
  3. Reinstall Node.js if npm is missing
  4. Check npm location: which npm or where npm

Issue: Permission Errors (macOS/Linux)

Global installs failing:

sudo npm install -g package-name

Better solution - Change npm prefix:

mkdir ~/.npm-global
npm config set prefix '~/.npm-global'

Add to ~/.bashrc or ~/.zshrc:

export PATH=~/.npm-global/bin:$PATH

Issue: Version Conflicts

Multiple Node.js versions:

  • Use version manager (nvm, fnm)
  • Uninstall conflicting versions
  • Use version manager to switch versions

Issue: Outdated npm

Update npm:

npm install -g npm@latest

Clear npm cache:

npm cache clean --force

Best Practices

Version Selection

  1. Use LTS for Production: LTS versions are stable and supported longer
  2. Use Current for Development: Try new features, but test thoroughly
  3. Match Team Versions: Use same version as your team
  4. Check Project Requirements: Some projects specify Node.js versions

Installation Location

  1. Default Locations: Usually fine for most users
  2. Custom Locations: Only if you have specific requirements
  3. Version Managers: Recommended for developers working on multiple projects

Maintenance

  1. Regular Updates: Keep Node.js and npm updated
  2. Security Patches: Install security updates promptly
  3. Clean Uninstalls: Remove old versions to avoid conflicts
  4. Backup Configurations: Save npm configuration if customized

Project Management

  1. Use package.json: Always use package.json for project dependencies
  2. Lock Files: Commit package-lock.json to version control
  3. Node Version: Specify Node.js version in .nvmrc or package.json
  4. CI/CD: Use same Node.js version in CI/CD as development

Security

  1. Audit Dependencies: Regularly run npm audit
  2. Update Dependencies: Keep dependencies updated
  3. Use Trusted Sources: Only install from npm registry or trusted sources
  4. Review Packages: Check package reputation before installing

Conclusion

Installing Node.js and npm is straightforward with the right method for your platform:

  • Windows: Official installer is easiest
  • macOS: Homebrew or official installer
  • Linux: Use NodeSource repository for latest versions
  • Multiple Versions: Use version managers (nvm, fnm)

After installation:

  1. Verify with node --version and npm --version
  2. Test with a simple script
  3. Keep both updated regularly
  4. Use version managers for flexibility

Node.js and npm are essential tools for modern JavaScript development. Proper installation and maintenance ensure a smooth development experience.

npm Node.js JavaScript Development Installation
Advertisement

Get weekly notes in your inbox

Practical tips, tutorials and resources. No spam.