Install Node.js with nvm and switch versions step by step
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:
curlorwget, and permission to edit your shell profile (~/.bashrc,~/.zshrc, etc.). - On Windows 10/11: have
wingetorchocoavailable.
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:
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bashWith wget:
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bashLoad nvm into your current shell without restarting:
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:
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"' >> ~/.bashrcFor Zsh:
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"' >> ~/.zshrcWindows: install nvm-windows
With winget:
winget install -e --id CoreyButler.NVMforWindowsOr Chocolatey:
choco install nvm -yClose 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:
nvm ls-remote --ltsInstall and use the latest LTS:
nvm install --lts
nvm use --ltsWindows
List available versions, identify the current LTS, and replace the example below with that number:
nvm list availableInstall and activate the current LTS. Replace 20.18.1 with the LTS you saw:
nvm install 20.18.1
nvm use 20.18.1Note: 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
nvm alias default lts/*Windows
Pick the version you want as default. Again, replace with your LTS:
nvm use 20.18.1On 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:
cd MY_PROJECT
echo "20.18.1" > .nvmrc
nvm useOn Windows, read the file and pass it to nvm:
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.
corepack enableIf you want to pin a specific version per project:
corepack prepare yarn@stable --activate
corepack prepare pnpm@latest --activateThen 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:
node -v
npm -vOn Windows:
node -v
npm -vExpected output (example):
v20.18.1
10.8.2If you like checking paths: on Linux/macOS/WSL
which nodeOn Windows:
where nodeCommon errors and how to fix them
-
nvm: command not foundon Linux/macOS/WSLFix: your shell isn't loading nvm. Run:
Bashexport NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"If that works, append it to
~/.bashrcor~/.zshrcas shown earlier and reopen the terminal. -
N/A: version "X.Y.Z" is not yet installedwhen runningnvm useFix: install that version first. For example:
Bashnvm install 20.18.1 nvm use 20.18.1 -
Windows:
'node' is not recognized as an internal or external commandFix: run
nvm use <version>in a fresh terminal after installing. If it persists, close all terminals, reopen, checkwhere node, and verify the version is installed withnvm list. -
Windows:
Access is denied.or issues switching versionsFix: close processes using Node (dev servers, IDEs). If needed, kill them:
PowerShelltaskkill /F /IM node.exeTry 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:
nvm uninstall 18.19.1On Windows:
nvm uninstall 18.19.1Field 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.