Skip to main content

Installing NVM and Node.js on Ubuntu

Install NVM (Node Version Manager)​

  1. Update your package index:

    sudo apt update
  2. Install prerequisites:

    sudo apt install curl build-essential -y
  3. Download and run the NVM installation script:

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash
  4. Close and reopen your terminal, or run this to apply changes immediately:

    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
  5. Verify NVM installation:

    nvm --version

Install Node.js using NVM​

  1. To install the latest LTS (Long Term Support) version:

    nvm install --lts

    Or install a specific version:

    nvm install 18.18.0
  2. Set your default Node.js version:

    nvm alias default 'lts/*'

    Or specify a version:

    nvm alias default 18.18.0
  3. Verify the installation:

    node --version
    npm --version

Managing Node.js Versions with NVM​

  • List installed versions:

    nvm ls
  • List available versions to install:

    nvm ls-remote
  • Switch between versions:

    nvm use 16.20.0

NVM makes it easy to switch between different Node.js versions for different projects.