NVM for Windows

repository·master·Indexed 13 days ago

https://github.com/coreybutler/nvm-windows

A Node.js version manager specifically designed for Windows users, allowing them to install and switch between different Node.js versions using a symlink approach. It includes a CLI for managing versions (v1.1.12 stable, v1.2.x latest), configuring mirrors and proxies, and managing architectures (32, 64, arm64). This project is distinct from the Mac/Linux nvm-sh.

Tokens
5K
Snippets
24
Records
34
Agent score
99%

What's inside NVM for Windows

  1. Overview of NVM for Windows

    master

    NVM for Windows is a Node.js version manager for Windows, recommended by Microsoft, npm, and Google.

    Important Distinction: This project is not the same as the original nvm (nvm-sh). The original nvm is designed for Mac/Linux only and follows a different philosophy. NVM for Windows is a separate project built specifically for the Windows environment.

    Project Status: The maintainers are currently developing Runtime (rt), which is the intended successor to NVM for Windows.

  2. Choosing between Latest and Stable versions

    master

    When downloading NVM for Windows, you may encounter two version tracks:

    1. Latest (v1.2.x): This is a transition version used while the team completes work on the successor, Runtime. Note that there is a known bug in this version that may impact users attempting to install old (End-of-Life/EOL) versions of Node.js.
    2. Stable (v1.1.12): This is the recommended version for most users, as it supports most EOL versions of Node.js without the known bugs present in the transition version.
  3. How nvm-windows manages Node versions via symlinks

    master

    Unlike other version managers that modify the system PATH or use .bat file redirection, nvm-windows uses a symlink approach.

    During installation, a single symlink is placed in the system PATH. When you execute nvm use <version>, the utility updates the target of that symlink to point to the directory of the selected Node installation.

    Key benefits of this approach:

    • Persistence: The active version persists across system reboots.
    • Global Updates: When you run nvm use, the active version is automatically updated across all currently open console windows.
    • No Per-Session Setup: You do not need to run nvm use every time you open a new terminal window; once a version is set, it remains active.
  4. Install nvm-windows

    master

    To install nvm-windows, use the latest installer from the official releases page.

    Important Pre-installation Steps:

    • Uninstall any pre-existing Node.js installations. This is the most reliable way to avoid PATH conflicts and permission issues. If you do not uninstall existing versions, nvm use may appear to do nothing because the original installation remains higher in your system PATH.
    • Delete existing Node.js directories (e.g., %ProgramFiles%\nodejs) to ensure NVM's symlink can be created successfully. A symlink cannot overwrite a physical directory.
    • Backup global npmrc config (e.g., %AppData%\npm\etc\npmrc) and consider moving settings to the user config %UserProfile%\.npmrc.
    • Delete existing npm install locations (e.g., %AppData%\npm) to prevent global module conflicts.

    After installation, if nvm is not recognized, restart your terminal or PowerShell (a full computer restart is usually not required).

    Download the latest installer from: https://github.com/coreybutler/nvm/releases
  5. Upgrade nvm-windows

    master

    Since v1.1.8, you can upgrade nvm-windows by simply running the new installer. The installer will safely overwrite the necessary files to update the tool without affecting your existing Node.js installations.

    Requirement: Ensure you use the same installation and symlink folders as your previous version. If you used default locations, you can simply proceed through the installer windows with 'Next'.

  6. Build nvm-windows from source

    master

    To build the project from source, follow these steps:

    1. Install Go.
    2. Clone the repository.
    3. (Optional) If building a 64-bit executable, change GOARCH to amd64 in build.bat.
    4. Open a Windows command prompt in the project directory.
    5. Run go get github.com/blang/semver.
    6. Run go get github.com/olekukonko/tablewriter.
    7. Execute build.bat.
    8. The generated setup program will be in the dist directory.
    go get github.com/blang/semver
    go get github.com/olekukonko/tablewriter
    build.bat
  7. How NVM architecture modes work

    master

    NVM for Windows allows you to switch between 32-bit and 64-bit Node.js executables.

    • You can specify the architecture during installation: nvm install <version> 64 or nvm install <version> 32.
    • You can switch the architecture of the currently selected version using: nvm use <arch> (e.g., nvm use 64).
    • You can check the current mode using nvm arch.

    Note that the architecture is constrained by your system's PROCESSOR_ARCHITECTURE environment variable.

  8. Troubleshoot NVM4W with the debug command

    master

    If you are experiencing issues with Node.js installations, environment variables, or permissions, use the nvm debug command. It performs a comprehensive check of your local environment, including:

    • PATH conflicts: Detects if other Node.js installations are blocking NVM.
    • Permissions: Checks for Administrator or Elevated rights and Windows Developer Mode status.
    • Console Support: Verifies if you are using a supported terminal (Command Prompt or PowerShell).
    • Symlink Integrity: Validates the NVM_SYMLINK path and its validity.
    • Connectivity: Tests connections to Node.js mirrors and checks for IPv6 slowdown issues.
    • Installation Validity: Checks if installed versions are missing node.exe or npm.cmd.
    • Update Status: Checks for available NVM upgrades.
  9. Manage global utilities across Node versions

    master

    Global npm modules (like yarn) are not shared between different Node.js versions. When you switch to a new Node.js version using nvm use, you must reinstall any global utilities you require for that specific version.

    Example: Reinstalling Yarn for multiple versions

    nvm use 14.0.0
    npm install -g yarn
    nvm use 12.0.1
    npm install -g yarn
    nvm use 14.0.0
    npm install -g yarn
    nvm use 12.0.1
    npm install -g yarn
  10. Configure NVM mirrors and proxies

    master

    You can configure mirrors for Node.js and npm downloads, which is particularly useful for users in regions with restricted access (e.g., China).

    • nvm node_mirror <node_mirror_url>: Set the Node.js mirror.
    • nvm npm_mirror <npm_mirror_url>: Set the npm mirror.
    • nvm proxy [url]: Set a proxy for downloads.
      • Leave [url] blank to view the current proxy.
      • Set [url] to none to remove the proxy.
    nvm node_mirror https://npmmirror.com/mirrors/node/
    nvm npm_mirror https://npmmirror.com/mirrors/npm/
  11. Use nvm-windows CLI commands

    master

    nvm-windows is a command-line tool that must be run in an Administrator shell (Command Prompt or PowerShell as Administrator) because it requires administrative rights to create symlinks.

    Core Commands

    • nvm install <version> [arch]: Installs a specific version, latest, or lts.
      • Use arch to specify 32, 64, or all (installs both).
      • Append --insecure to bypass SSL validation.
    • nvm use <version> [arch]: Switches the active Node.js version.
      • Supports latest, lts, or newest (the latest installed version).
      • Use nvm use <arch> to switch the architecture of the currently selected version.
    • nvm list [available]: Lists installed versions. Adding available shows versions available for download.
    • nvm current: Displays the currently active version.
    • nvm uninstall <version>: Removes a specific version.
    • nvm on/nvm off: Enables or disables Node.js version management (does not uninstall versions).
    • nvm debug: Checks the NVM4W process for known problems (useful for detecting PATH conflicts).
    • nvm version: Displays the current version of nvm-windows.
    • nvm root <path>: Sets or displays the directory where Node.js versions are stored.
    • nvm arch [32|64]: Shows current architecture or overrides it.
    nvm install lts
    nvm use lts