NVM Installed: Managing and Switching Node.js Versions

September, 20th 2024 2 min read

Node Version Manager (NVM) is one of the most useful tools for any JavaScript or backend developer. It allows you to install, switch, and manage multiple Node.js versions on the same machine without conflicts. If you’ve ever run into “works on my machine” issues or maintained several projects requiring different Node versions, NVM solves that problem cleanly.

Below is an improved and expanded guide with clearer explanations, updated tips, and practical examples.


1. Check Installed Node Versions

To check which Node.js versions are currently installed on your system:

bash
nvm list

To check which versions are available remotely:

bash
nvm ls-remote

Useful for finding long-term support (LTS) releases or older versions required by legacy apps.


2. Install a New Node.js Version

Install a specific version:

bash
nvm install 18.20.4

Install the latest LTS version:

bash
nvm install --lts

Install the latest version overall:

bash
nvm install latest

Pro tip

You can also install from a specific release line, for example:

bash
nvm install 20

This installs the most recent 20.x.x release.


3. Switch Between Node Versions

Make a version active in the current terminal session:

bash
nvm use 20.17.0

Confirm the version currently in use:

bash
node -v

If your shell opens a new tab or window, you must run nvm use again or set a default.


4. Set a Default Node.js Version

To automatically load a specific Node.js version every time your terminal opens:

bash
nvm alias default 18.20.4

To see all aliases:

bash
nvm alias

5. Uninstall Node.js Versions You No Longer Need

Remove an installed version:

bash
nvm uninstall 12.22.1

This cleans up space and keeps your NVM environment tidy.


6. Overview of Useful NVM Commands

CommandDescription
nvm install latestInstall newest Node.js version
nvm install --ltsInstall newest LTS release
nvm lsList installed versions
nvm ls-remoteList all available versions
nvm alias defaultSet a default version
nvm uninstallUninstall a version
nvm currentShow currently active version

7. Troubleshooting NVM

NVM command not found

Make sure your shell config contains NVM initialization lines.

For zsh (.zshrc):

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

Node still showing older version

Your shell might be caching paths. Run:

bash
hash -r

or simply restart the terminal.

Running NVM in scripts

NVM only loads inside interactive shells unless explicitly sourced:

bash
source ~/.nvm/nvm.sh
nvm use 18

8. Why Developers Love NVM

  • Test apps across multiple Node versions
  • Avoid breaking global dependencies
  • Keep legacy and modern projects working side-by-side
  • Easily switch between environments
  • Lightweight and works on macOS, Linux, and WSL

NVM is especially useful when upgrading frameworks like Next.js, NestJS, Express, or tools like Vite, which often require specific Node versions.


Final Notes

This guide is updated for NVM v0.39+ and supports installation of Node.js versions up to 22+.

Happy coding!