M
MeshWorld.
HowTo Node.js JavaScript Ubuntu macOS Windows Install nvm Developer Tools 4 min read

How to Install Node.js on Ubuntu, macOS and Windows

By Vishnu Damwala

Node.js has three or four ways to install it on any given system, and most tutorials send you to the official website download page. That method works, but it makes upgrading painful and conflicts with tools like nvm later.

Here’s the right way on each platform — the method that won’t cause headaches six months from now.

The short answer

  • Ubuntu/Linux → use nvm (Node Version Manager)
  • macOS → use nvm or Homebrew
  • Windows → use winget or nvm-windows

Install Node.js on Ubuntu / Debian Linux

nvm lets you switch Node.js versions per project. Essential if you work on multiple projects.

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

# Reload your shell config
source ~/.bashrc   # or ~/.zshrc if you use zsh

# Install the latest LTS version
nvm install --lts

# Verify
node -v
npm -v

To install a specific version:

nvm install 20
nvm use 20
nvm alias default 20   # makes v20 the default in new terminals

Method 2: NodeSource repository (if you want a system-wide install)

# Add NodeSource repo for Node.js 20 LTS
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -

# Install
sudo apt-get install -y nodejs

# Verify
node -v
npm -v

Method 3: Snap (quick but slower startup)

sudo snap install node --classic

Install Node.js on macOS

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

# Restart terminal or source your profile
source ~/.zshrc

# Install LTS
nvm install --lts

# Verify
node -v
npm -v

Method 2: Homebrew

# Install Homebrew first if you don't have it
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install Node.js
brew install node

# Verify
node -v
npm -v

Homebrew installs a fixed version. Use brew upgrade node to update it later.


Install Node.js on Windows

Open PowerShell or Command Prompt:

winget install OpenJS.NodeJS.LTS

Restart your terminal after installation.

node -v
npm -v

Method 2: nvm-windows

nvm-windows is a separate project from nvm but works similarly:

  1. Download the installer from github.com/coreybutler/nvm-windows/releases — get nvm-setup.exe
  2. Run the installer
  3. Open a new Command Prompt or PowerShell as Administrator
nvm install lts
nvm use lts

node -v
npm -v

Method 3: Official installer (works, but harder to manage)

Download from nodejs.org and run the .msi installer. Fine for a single-version setup, but harder to upgrade or switch versions later.


After installation — verify everything works

node -v      # should print v20.x.x or similar
npm -v       # should print 10.x.x or similar
npx -v       # comes with npm

Create a quick test:

node -e "console.log('Node.js is working')"

Which package manager: npm, pnpm, or yarn?

Node.js comes with npm by default. Many developers switch to pnpm for faster installs and better disk usage:

npm install -g pnpm
pnpm -v

Or yarn:

npm install -g yarn
yarn -v

Either works. pnpm is the fastest for large projects. npm is fine for everything else.


Updating Node.js

With nvm:

nvm install --lts          # installs new LTS
nvm alias default --lts    # sets it as default
nvm uninstall 18           # optionally remove old version

With Homebrew:

brew upgrade node

With winget:

winget upgrade OpenJS.NodeJS.LTS

Ready to containerize? Learn How to Write a Production Dockerfile for Node.js.