DEV Community

Cover image for NVM Install On Your PC
Anush
Anush

Posted on

NVM Install On Your PC

NVM (Node Version Manager) is a popular tool for managing multiple versions of Node.js on a single machine. Here are some important commands for NVM:

Installation Commands

  1. Install NVM:
 curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
Enter fullscreen mode Exit fullscreen mode

This script installs the latest version of NVM. Replace `v0.

NVM (Node Version Manager) Important Commands

Installation

  1. Install NVM:


curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash

This command downloads and runs the NVM install script from the NVM GitHub repository.

  1. Load NVM:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

This is usually added to your shell profile file (~/.bashrc, ~/.zshrc, etc.) to load NVM when you open a new terminal.

Basic Usage

  1. Check NVM Version:


nvm --version

  1. List Installed Node Versions:


nvm ls

  1. List Available Node Versions:

    nvm ls-remote

  2. Install a Specific Node Version:


nvm install <version>

Replace <version> with the desired version number, e.g., nvm install 16.13.0.

  1. Use a Specific Node Version:


nvm use <version>

Replace <version> with the installed version number you want to use.

  1. Set Default Node Version:


nvm alias default <version>

This sets the default Node.js version to be used in new shell sessions.

  1. Uninstall a Specific Node Version:


nvm uninstall <version>

  1. Show Current Node Version:

    nvm current

  2. Run Node with a Specific Version:


nvm run <version> <script.js>

Replace `<version>` with the Node.js version and `<script.js>` with the script you want to run.
Enter fullscreen mode Exit fullscreen mode
  1. Execute NPM Commands with Specific Node Version:

    nvm exec <version> npm <command>

    For example, nvm exec 14.17.0 npm install.

  2. Reinstall Packages from Current Version:

    nvm reinstall-packages <version>

    This reinstalls global packages from the specified version into the current version.

  3. Get Help:


nvm help

These commands cover the essential functionality of NVM, helping you to manage different Node.js versions efficiently.

Top comments (0)