How to set your default Node.js version using NVM [4 Ways]

avatar
Borislav Hadzhiev

Last updated: Apr 5, 2024
4 min

banner

# Table of Contents

  1. How to set your default Node.js version using NVM
  2. Setting the latest Node.js version as the default using NVM
  3. Setting the long-term supported Node.js version as the default using NVM
  4. Seeing the old Node.js version in VS Code

# How to set your default Node.js version using NVM

You can use the nvm alias default 18.16.0 command to set your default Node.js version using NVM.

The command sets your default Node version that is used in any new shell.

First, install the version that you want to set as default.

shell
nvm install 18.16.0

install version you want to use as default

Then set the version as your default Node.js version.

shell
nvm alias default 18.16.0 nvm use 18.16.0

set specific node js version as default using nvm

Make sure to replace 18.16.0 with your preferred Node.js version.

The nvm alias default command is used to set a default Node.js version to be used in any new shell.

If you need to check which Node.js versions are installed, use the nvm ls command.

shell
nvm ls

check currently installed node js versions using nvm

Notice that the currently active Node.js version has an arrow pointing to it.

You can also use the node -v or node --version command to check your current Node.js version.

shell
node -v node --version

check current node js version

If you need to list what Node.js versions are available to install, use the nvm ls-remote command.

shell
nvm ls-remote

nvm ls remote

The output of the command is quite long as it shows each Node.js version that can be installed using NVM.

If you try to set a version that you haven't installed as your default, you would get an error.

shell
# ⛔️ ! WARNING: Version '19.5.0' does not exist. # default -> 19.5.0 (-> N/A) nvm alias default 19.5.0

setting version that is not installed as default

I don't have version 19.5.0 installed on my machine, so trying to set it as the default Node.js version raises an error.

You first have to install the version.

shell
nvm install 19.5.0 nvm use 19.5.0

install specific version before setting as default

And then set it as your default Node.js version.

shell
nvm alias default 19.5.0

set installed version as default

If the node -v command doesn't show the expected version, try to restart your shell.

After you set a certain Node.js version as your default, all new shells will start with the specified version.

You can also use the nvm use default command to switch to the default version once it has been set.

shell
nvm use default

switch to default version once set

# Setting the latest Node.js version as the default using NVM

If you need to set the latest Node.js version that is installed on your PC as the default using NVM, issue the following command.

shell
nvm alias default node nvm use node

set latest installed version as default

shell
node -v

The command sets your default Node.js version to the latest Node version that is installed on your computer.

The latest Node.js version that is installed on my PC is 20.0.0.

If you need to set your default Node.js version to the latest Node.js remote version:

  1. Run the following command to install the latest version.
shell
nvm install node

install latest node js version using nvm

  1. Make the latest version the default and switch to it.
shell
nvm alias default node nvm use node

make latest node version default and switch to it

# Setting the long-term supported Node.js version as the default using NVM

If you need to set the long-term supported Node.js version as the default, use the following commands.

  1. Install the long-term supported Node.js version using NVM.
shell
nvm install --lts nvm use --lts

install lts node version using nvm

  1. Set the LTS Node.js version as your default.
shell
nvm alias default 'lts/*'

set node lts version as your default

If the command doesn't work for you, try to wrap lts/* in double quotes.

shell
nvm alias default "lts/*"

# Seeing the old Node.js version in VS Code

If you still see the old version after setting a default Node.js version in VS Code.

  1. Try to restart VS Code.

  2. Try to completely close the IDE and reopen it.

  3. Try to clear the cache in VS Code.

  4. Try to rerun the node -v or node --version command in a new terminal window.

shell
node -v node --version

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.