Node Version Manager (nvm-windows): A Basic Guide

Node Version Manager (NVM) is an essential tool for Node.js developers that allows you to easily manage multiple Node.js versions on a single machine. This flexibility is invaluable when working across different projects with varying Node.js version requirements.

What is NVM?

NVM is a version manager for Node.js, designed to be installed per-user and invoked per-shell. It allows you to:

  • Install and maintain multiple Node.js versions
  • Switch between different versions with a single command
  • Set a default Node.js version for your environment
  • Use different Node.js versions in different terminal sessions

Official NVM Repository: https://github.com/coreybutler/nvm-windows

Uninstalling Existing Node.js

Before installing NVM, it’s recommended to uninstall any existing Node.js installations to prevent conflicts.

For Windows:

  1. Go to Control Panel > Programs > Uninstall a program
  2. Find Node.js in the list and uninstall it
  3. Delete any remaining Node.js and npm directories:
    • C:\Program Files\nodejs
    • C:\Program Files (x86)\nodejs
    • C:\Users\{username}\AppData\Roaming\npm
    • C:\Users\{username}\AppData\Roaming\npm-cache
  4. Check environment variables and remove any Node.js references
  5. Restart your computer

Installing NVM

For Windows:

For Windows, there’s a separate project called nvm-windows:

  1. Download the installer from nvm-windows releases
  2. Run the installer and follow the installation wizard
  3. Restart your terminal after installation

Basic NVM Usage

Once installed, you can use these commands to manage your Node.js versions:

List Available Node.js Versions

1
nvm ls available

2025-03-23-20-15-48

Install a Specific Node.js Version

1
2
3
4
nvm install 18.16.0    # Install specific version
nvm install 18 # Install latest 18.x.x version
nvm install lts # Install latest LTS version
nvm install node # Install latest available version

List Installed Node.js Versions

1
nvm ls

2025-03-23-20-16-55

Switch Between Node.js Versions

1
2
3
nvm use 16.20.0        # Use specific version
nvm use 16 # Use latest installed 16.x.x version
nvm use lts # Use latest installed LTS version

Advanced Usage

Project-Specific Node.js Version

Create a .nvmrc file in your project root containing the Node.js version:

1
18.16.0

Then in the project directory, simply run:

1
nvm use

This will automatically switch to the version specified in the .nvmrc file.

Running with Path

1
nvm run 16.20.0 app.js    # Run app.js using Node.js 16.20.0

Node Version Manager (nvm-windows): A Basic Guide
https://www.hardyhu.cn/2024/12/23/Node-Version-Manager-NVM-Windows-A-Basic-Guide/
Author
John Doe
Posted on
December 23, 2024
Licensed under