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:
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
Method 1: Official Installer (Recommended for Beginners)
The easiest way to install Node.js on Windows:
- Visit nodejs.org
- Download the LTS (Long Term Support) version for Windows
- Run the installer (.msi file)
- Follow the installation wizard
- Check “Automatically install necessary tools” if prompted
- Restart your computer if required
- 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
Method 3: Using Winget (Recommended for power users)
Windows Package Manager — built into Windows 10/11, no extra setup needed:
Method 4: Using Scoop
If you use Scoop package manager:
scoop install nodejs
macOS Installation
Method 1: Official Installer
The simplest method for macOS:
- Visit nodejs.org
- Download the macOS installer (.pkg file)
- Open the downloaded file
- Follow the installation wizard
- Verify: Open Terminal and run
node --version
Method 2: Using Homebrew (Recommended)
Homebrew is the most popular package manager for macOS. One command and you’re done:
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):
Linux Installation
Ubuntu/Debian
Method 1: Using NodeSource Repository (Recommended)
The default Ubuntu/Debian repos ship outdated Node — use NodeSource for the actual LTS:
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:
- Download from github.com/coreybutler/nvm-windows/releases
- Run the installer
- 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):
- Download latest installer from nodejs.org
- Run installer (it will update existing installation)
- 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:
- Verify Node.js is installed:
node --version - npm should come with Node.js
- Reinstall Node.js if npm is missing
- Check npm location:
which npmorwhere 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
- Use LTS for Production: LTS versions are stable and supported longer
- Use Current for Development: Try new features, but test thoroughly
- Match Team Versions: Use same version as your team
- Check Project Requirements: Some projects specify Node.js versions
Installation Location
- Default Locations: Usually fine for most users
- Custom Locations: Only if you have specific requirements
- Version Managers: Recommended for developers working on multiple projects
Maintenance
- Regular Updates: Keep Node.js and npm updated
- Security Patches: Install security updates promptly
- Clean Uninstalls: Remove old versions to avoid conflicts
- Backup Configurations: Save npm configuration if customized
Project Management
- Use package.json: Always use package.json for project dependencies
- Lock Files: Commit package-lock.json to version control
- Node Version: Specify Node.js version in .nvmrc or package.json
- CI/CD: Use same Node.js version in CI/CD as development
Security
- Audit Dependencies: Regularly run
npm audit - Update Dependencies: Keep dependencies updated
- Use Trusted Sources: Only install from npm registry or trusted sources
- 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:
- Verify with
node --versionandnpm --version - Test with a simple script
- Keep both updated regularly
- 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.