Intro

Node version manager (NVM) allows you to run different version of Node on your system which is very helpful for testing and ensuring that the Node version you test on is the same as the Node version you run in production.

This is just a quick post on how to install and use (NVM) on Ubuntu 2004.

Software

The following software versions are used in this post

  • Ubuntu - 2004
  • NVM - 0.35.3

Installation

Install NVM

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

Update ~/.zshrc

~/.zshrc
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 loads nvm
Note
Restart your shell.

Verify installation.

cmd
nvm --version

# output
0.35.3  

Usage

Install the latest release of Node.

cmd
nvm install node

# Output
Downloading and installing node v14.6.0...
Downloading https://nodejs.org/dist/v14.6.0/node-v14.6.0-linux-x64.tar.xz...
################################################################################################################# 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v14.6.0 (npm v6.14.6)
Creating default alias: default -> node (-> v14.6.0)

Set latest release of Node as the Node version to use.

cmd
nvm use node

# output
Now using node v14.6.0 (npm v6.14.6)

Verify Node version in use.

cmd
node --version

# output
v14.6.0
cmd
which node

# output
/home/bradmin/.nvm/versions/node/v14.6.0/bin/node

Verify NPM version in use.

cmd
which npm

# output
/home/bradmin/.nvm/versions/node/v14.6.0/bin/npm

Outro

In this post we installed NVM and used it to install and use the latest version of NodeJS.