Install Node.js with nvm and switch versions step by step

Tutorials By 5 min read

Install Node.js with nvm on Linux, macOS, and Windows. I'll show you how to install LTS, set a default version, and use .nvmrc per project.

Install Node.js with nvm is the safest way to run multiple versions without wrecking your machine. In this guide you'll install nvm, grab the LTS release of Node, set a default version, and configure .nvmrc so each project uses the right one. Copy, paste, done.

Requirements to install Node.js with nvm

  • Linux, macOS, or WSL2 on Windows (for nvm). On native Windows we'll use nvm-windows.
  • Internet access and a terminal.
  • On Linux/macOS: curl or wget, and permission to edit your shell profile (~/.bashrc, ~/.zshrc, etc.).
  • On Windows 10/11: have winget or choco available.

Step 1: install the version manager

First we install the tool that manages Node versions. On Linux/macOS/WSL use nvm; on native Windows, nvm-windows.

Linux/macOS/WSL: install nvm

With curl:

Bash
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

With wget:

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

Load nvm into your current shell without restarting:

Bash
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"

If nvm doesn't load after reopening the terminal, add these lines to your profile. For Bash:

Bash
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bashrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"' >> ~/.bashrc
echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"' >> ~/.bashrc

For Zsh:

Bash
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.zshrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"' >> ~/.zshrc
echo '[ -s "$NVM_DIR/bash_completion" ] && . "$NVM_DIR/bash_completion"' >> ~/.zshrc

Windows: install nvm-windows

With winget:

PowerShell
winget install -e --id CoreyButler.NVMforWindows

Or Chocolatey:

PowerShell
choco install nvm -y

Close and reopen your terminal. Pro tip: use Windows Terminal and open a brand new window, not a tab from the old session.

Step 2: install Node.js LTS

LTS is what you want for most cases. Stable, longer support, fewer surprises.

Linux/macOS/WSL

List available LTS versions and pick one if you want to be explicit:

Bash
nvm ls-remote --lts

Install and use the latest LTS:

Bash
nvm install --lts
nvm use --lts

Windows

List available versions, identify the current LTS, and replace the example below with that number:

PowerShell
nvm list available

Install and activate the current LTS. Replace 20.18.1 with the LTS you saw:

PowerShell
nvm install 20.18.1
nvm use 20.18.1

Note: the version number is an example. Use the LTS shown by your list.

Step 3: set a default version

So every new shell starts with something sane.

Linux/macOS/WSL

Bash
nvm alias default lts/*

Windows

Pick the version you want as default. Again, replace with your LTS:

PowerShell
nvm use 20.18.1

On nvm-windows, the version you use becomes the default for new terminals.

Step 4: use a project-specific version with .nvmrc

This is the clean way to work. Declare in the repo which Node version the project expects. Less arguing, more shipping.

From your project root, create .nvmrc with the exact version (better than an alias) and activate it:

Bash
cd MY_PROJECT
echo "20.18.1" > .nvmrc
nvm use

On Windows, read the file and pass it to nvm:

PowerShell
cd MY_PROJECT
type .nvmrc
nvm use (Get-Content .nvmrc)

Tip: commit .nvmrc to the repo. Your teammates (and CI) will thank you.

Step 5: align your package manager with Corepack (optional but useful)

If you use Yarn or pnpm, enable Corepack so the project sticks to the declared version automatically.

Bash
corepack enable

If you want to pin a specific version per project:

Bash
corepack prepare yarn@stable --activate
corepack prepare pnpm@latest --activate

Then in package.json you can declare packageManager with its version. Clones will pick it up automatically.

Verify it worked

Test Node and npm. On Linux/macOS/WSL:

Bash
node -v
npm -v

On Windows:

PowerShell
node -v
npm -v

Expected output (example):

Texto
v20.18.1
10.8.2

If you like checking paths: on Linux/macOS/WSL

Bash
which node

On Windows:

PowerShell
where node

Common errors and how to fix them

  • nvm: command not found on Linux/macOS/WSL

    Fix: your shell isn't loading nvm. Run:

    Bash
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"

    If that works, append it to ~/.bashrc or ~/.zshrc as shown earlier and reopen the terminal.

  • N/A: version "X.Y.Z" is not yet installed when running nvm use

    Fix: install that version first. For example:

    Bash
    nvm install 20.18.1
    nvm use 20.18.1
  • Windows: 'node' is not recognized as an internal or external command

    Fix: run nvm use <version> in a fresh terminal after installing. If it persists, close all terminals, reopen, check where node, and verify the version is installed with nvm list.

  • Windows: Access is denied. or issues switching versions

    Fix: close processes using Node (dev servers, IDEs). If needed, kill them:

    PowerShell
    taskkill /F /IM node.exe

    Try again and, if needed, run the terminal as Administrator and execute nvm use <version>.

FAQ

Should I use LTS or Current

For production and teams, LTS. It's stable and supported longer. Use Current only if you need bleeding-edge features and accept the risk.

How do I upgrade to a new LTS without breaking projects

Install the new LTS and set it as default. Keep .nvmrc pinned per repo to the version you've validated. Your system gets the latest LTS, each repo stays put until you update it.

Is it a good idea to put lts/* in .nvmrc

I don't recommend it. Use an exact number to avoid inconsistent builds the day LTS changes.

Will it break if I also have a system-installed Node

It can. PATH conflicts are common. My advice: remove system/Homebrew Node and let nvm handle everything.

How do I uninstall a version I no longer need

Easy. On Linux/macOS/WSL:

Bash
nvm uninstall 18.19.1

On Windows:

PowerShell
nvm uninstall 18.19.1

Field note

Two habits that saved me hours: 1) commit .nvmrc, 2) don't mix system Node with nvm. And when a build goes sideways, take a breath, run nvm use at the repo root, and move on.

Related posts

More categories