How to install nvm in windows

Learn how to install nvm in windows with practical examples, diagrams, and best practices. Covers nvm development techniques with visual explanations.

Mastering Node.js Versions: A Comprehensive Guide to Installing NVM on Windows

Hero image for How to install nvm in windows

Learn how to install and manage multiple Node.js versions on your Windows machine using Node Version Manager (NVM) for Windows. This guide covers installation, common commands, and troubleshooting.

Node.js is a powerful JavaScript runtime, but different projects often require different Node.js versions. Managing these versions manually can be a hassle. This is where Node Version Manager (NVM) comes in. While NVM is primarily known for Linux/macOS, there's a dedicated NVM for Windows project that provides similar functionality. This article will walk you through the process of installing and using NVM on your Windows system, enabling you to effortlessly switch between Node.js versions.

Why Use NVM for Windows?

NVM for Windows offers several compelling advantages for developers:

  • Multiple Node.js Versions: Easily install and switch between different Node.js versions required by various projects without conflicts.
  • Project Compatibility: Ensure your projects run with the exact Node.js version they were developed for, preventing compatibility issues.
  • Simplified Management: A command-line interface simplifies the process of installing, uninstalling, and switching Node.js versions.
  • npm Management: Each Node.js installation comes with its own npm (Node Package Manager), ensuring package dependencies are isolated per Node.js version.
flowchart TD
    A[Start] --> B{Need specific Node.js version?}
    B -- Yes --> C[Install NVM for Windows]
    C --> D[Install desired Node.js versions via NVM]
    D --> E[Switch between versions using NVM commands]
    E --> F[Develop/Run projects]
    B -- No --> G[Continue with existing Node.js]
    F --> H[End]
    G --> H

Workflow for managing Node.js versions with NVM for Windows

Prerequisites and Initial Setup

Before installing NVM for Windows, it's crucial to ensure your system is prepared. If you have any existing Node.js installations, especially those installed via an .msi installer, they must be uninstalled first. NVM for Windows manages its own installations and conflicts can arise if previous versions are present in your system's PATH.

  1. Uninstall Existing Node.js: Go to 'Add or remove programs' in Windows settings and uninstall any Node.js or npm installations.
  2. Remove Existing npm Global Modules: If you had global npm modules, it's good practice to clear them. You can usually find them in %APPDATA%\npm and %APPDATA%\npm-cache.
  3. Verify PATH Environment Variable: After uninstalling, check your system's PATH environment variables to ensure no lingering Node.js or npm paths remain. If they do, remove them manually.

Installation Steps for NVM for Windows

The installation process for NVM for Windows is straightforward. You'll download an installer from the official GitHub repository.

1. Download the Installer

Navigate to the official NVM for Windows GitHub repository releases page: https://github.com/coreybutler/nvm-windows/releases. Download the latest nvm-setup.zip file.

2. Extract and Run the Installer

Extract the contents of the downloaded nvm-setup.zip file. Inside, you'll find nvm-setup.exe. Run this executable as an administrator.

3. Follow the Installation Wizard

The installer will guide you through the setup process. You'll be prompted to choose the installation directory for NVM and the directory where Node.js versions will be installed. It's generally recommended to use the default paths unless you have specific reasons not to.

4. Verify Installation

Once the installation is complete, open a new Command Prompt or PowerShell window (do not use an existing one, as it might not have the updated PATH). Type nvm version and press Enter. You should see the installed NVM version. If you receive an error, restart your computer and try again.

nvm version

Verifying NVM for Windows installation

Using NVM for Windows: Essential Commands

With NVM installed, you can now manage your Node.js versions with ease. Here are the most common and essential commands you'll use.

1. Install a Node.js Version

To install a specific Node.js version, use the nvm install command followed by the version number. For example, to install Node.js version 16.13.0, you would run: nvm install 16.13.0. You can also install the latest stable version with nvm install latest or the latest LTS (Long Term Support) version with nvm install lts.

2. List Installed Versions

To see all Node.js versions currently installed on your system via NVM, use nvm list. The currently active version will be indicated.

3. Switch Node.js Versions

To switch to a different installed Node.js version, use nvm use followed by the version number. For example: nvm use 14.17.0. This command updates your system's PATH to point to the selected Node.js installation.

4. Uninstall a Node.js Version

If you no longer need a specific Node.js version, you can uninstall it using nvm uninstall followed by the version number: nvm uninstall 16.13.0. Make sure the version you're trying to uninstall is not currently in use.

# Install a specific version
nvm install 16.13.0

# Install the latest LTS version
nvm install lts

# List all installed versions
nvm list

# Switch to a specific version
nvm use 16.13.0

# Uninstall a version
nvm uninstall 16.13.0

Common NVM for Windows commands