Different projects often need different Node.js versions. One project runs on Node 18, another needs Node 22. nvm (Node Version Manager) lets you switch Node.js versions in WSL Ubuntu with a single command — no reinstalling, no conflicts.
The examples in this guide are run on WSL2 Ubuntu in Windows, but they work the same on any Ubuntu system.
Prerequisites
- WSL 2 with Ubuntu installed — see How to Install Ubuntu in WSL 2 on Windows if you need to set this up
Install nvm
Step 1: Download and Install nvm
Run the install script from the official nvm repository:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
This adds nvm to your shell profile (~/.bashrc or ~/.zshrc). Load it into your current session:
source ~/.bashrc
Verify nvm is working:
nvm --version
Step 2: Install a Node.js Version
Install the latest LTS (Long Term Support) version:
nvm install --lts
Or install a specific version:
nvm install 22
You can install as many versions as you need. They don’t conflict with each other.
nvm install 20
nvm install 18
Switch Between Node.js Versions
Step 3: Switch Versions with nvm use
Switch to any installed version:
nvm use 22
Check which version is active:
node -v
List all versions you have installed:
nvm ls
The active version is shown with an arrow (->) next to it.
Step 4: Set a Default Version
When you open a new terminal, nvm uses the default version. Set it with:
nvm alias default 22
Every new terminal session will now start with Node 22.
Use .nvmrc for Per-Project Versions
Instead of remembering which Node version each project needs, add a .nvmrc file to the project root:
echo "22" > .nvmrc
Then when you cd into the project, run:
nvm use
nvm reads the version from .nvmrc and switches automatically. This is useful when you work on multiple projects — you don’t have to remember which version each one needs.
Commit the .nvmrc file to your repo so the whole team uses the same Node version.
Useful nvm Commands
| Command | What it does |
|---|---|
nvm install --lts |
Installs the latest LTS version |
nvm install 22 |
Installs the latest Node 22.x release |
nvm use 20 |
Switches to Node 20 for the current session |
nvm alias default 22 |
Sets Node 22 as the default for new terminals |
nvm ls |
Lists all installed versions |
nvm ls-remote --lts |
Lists all available LTS versions |
nvm current |
Shows the currently active version |
nvm uninstall 18 |
Removes Node 18 from your system |
Uninstall a Node.js Version
If you no longer need a version, remove it to free up space:
nvm uninstall 18
You can’t uninstall the version that’s currently active. Switch to a different version first with nvm use.
Conclusion
With nvm installed, you can switch between any Node.js version in seconds. Use nvm alias default to set your go-to version and .nvmrc files to keep projects on the right version automatically.
If you also work with Python, check out How to Install and manage Python Versions on WSL Ubuntu — it covers pyenv, which works the same way as nvm but for Python. You might also want to connect VS Code to your WSL 2 instance for a better dev workflow.


