Article

Table of Contents
Theme:
Was this article helpful?
Try Vultr Today with

$50 Free on Us!

Want to contribute?

You could earn up to $600 by adding new articles!

Install NVM and Node.JS on Ubuntu 20.04

Last Updated: Mon, May 24, 2021
Programming System Admin Ubuntu

Introduction

Node Version Manager (NVM) allows you to install and switch between different versions of Node.JS using the command line. This article explains how to install Node Version Manager and Node.JS on Ubuntu 20.04.

Prerequisites

To complete this guide, make sure you have a fully-updated Vultr Ubuntu 20.04 server.

Install NVM

  1. SSH to the server.
  2. Install NVM. The following command installs the latest version of NVM into $HOME/.nvm.

    $ export NVM_DIR="$HOME/.nvm" && (
        git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR"
        cd "$NVM_DIR"
        git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
      ) && \. "$NVM_DIR/nvm.sh"
    
  3. Edit your ~/.bashrc file:

    $ nano ~/.bashrc
    

    Add the following lines at the end of the file:

    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
    
  4. Save and exit the file.

  5. Reload your ~/.bashrc to activate NVM.

    $ source ~/.bashrc
    
  6. Verify NVM is installed with the -v parameter. It should return the version number as shown.

    $ nvm -v
    0.38.0
    

Install Node.JS

To install a specific version of Node.JS, specify the desired version number.

$ nvm install 6.14.4

To install the latest release of node, use node, which is an alias for the latest version.

$ nvm install node

Test your node installation.

$ node -v

How to Upgrade NVM

If you manually installed NVM as described earlier, use this method to upgrade to the latest version.

SSH to the server, then run the following to update from GitHub.

$ (
    cd "$NVM_DIR"
    git fetch --tags origin
    git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
  ) && \. "$NVM_DIR/nvm.sh"

More Information

To learn more about how to use NVM, see the project documentation.

Want to contribute?

You could earn up to $600 by adding new articles