Steps to Install NVM & Node on Ubuntu 20.04 LTS with Examples

NVM stands for Node Version Manager tool. Using NVM,we can install & manage multiple node.js versions in a linux system & We can also install/choose specific version of node for applications. It provides an option to auto select Node version using .nvmrc configuration file. Node.js is a JavaScript platform used for general-purpose programming. It allows users to build network applications quickly.

There are few steps to install with example NVM on ubuntu:

Step 1: Update the System.

apt-get update

Step 2: Install the curl & Download the NVM installer script.

apt install curl
curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash

  • Here is the command output.

curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
root@ip-172-31-16-172:/home/ubuntu# curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 14984 100 14984 0 0 98k 0 --:--:-- --:--:-- --:--:-- 98k
=> Downloading nvm from git to '/root/.nvm'
=> Cloning into '/root/.nvm'...
remote: Enumerating objects: 348, done.
remote: Counting objects: 100% (348/348), done.
remote: Compressing objects: 100% (297/297), done.
remote: Total 348 (delta 39), reused 156 (delta 26), pack-reused 0
Receiving objects: 100% (348/348), 200.97 KiB | 8.74 MiB/s, done.
Resolving deltas: 100% (39/39), done.
* (HEAD detached at FETCH_HEAD)
master
=> Compressing and cleaning up git repository
=> Appending nvm source string to /root/.bashrc
=> Appending bash_completion source string to /root/.bashrc
=> Close and reopen your terminal to start using nvm or run the following to use it now:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

  • Run the following command to load the environment.

source ~/.profile

Step 3: To install the latest stable node version.

nvm install stable

  • Here is the command output.

root@ip-172-31-16-172:/home/ubuntu# nvm install stable
Downloading and installing node v17.0.0...
Downloading https://nodejs.org/dist/v17.0.0/node-v17.0.0-linux-x64.tar.xz...
######################################################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v17.0.0 (npm v8.1.0)
Creating default alias: default -> stable (-> v17.0.0)

  • Check the NVM version.

nvm --version

  • Here is the command output.

root@ip-172-31-16-172:/home/ubuntu# nvm --version
0.39.0

  • Check the Node version.

node --version

  • Here is the command output.

root@ip-172-31-16-172:/home/ubuntu# node --version
v17.0.0

  • To install latest Node version using –lts Option.

nvm install --lts

  • Here is the command output.

root@ip-172-31-16-172:/home/ubuntu# nvm install --lts
Installing latest LTS version.
Downloading and installing node v14.18.1...
Downloading https://nodejs.org/dist/v14.18.1/node-v14.18.1-linux-x64.tar.xz...
######################################################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v14.18.1 (npm v6.14.15)

  • Install a specific version of node.

nvm install version
nvm install 12

  • Here is the command output.

root@ip-172-31-16-172:/home/ubuntu# nvm install 12
Downloading and installing node v12.22.7...
Downloading https://nodejs.org/dist/v12.22.7/node-v12.22.7-linux-x64.tar.xz...
######################################################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v12.22.7 (npm v6.14.15)

  • To list installed version’s of Node.

nvm ls

  • Here is the command output.

root@ip-172-31-16-172:/home/ubuntu# nvm ls
-> v10.5.0
v14.18.1
v17.0.0
default -> stable (-> v17.0.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v17.0.0) (default)
stable -> 17.0 (-> v17.0.0) (default)
lts/* -> lts/fermium (-> v14.18.1)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.7 (-> N/A)
lts/fermium -> v14.18.1

  • To find available Node.js version.

nvm ls-remote

  • Here is the command output.

root@ip-172-31-16-172:/home/ubuntu# nvm ls-remote
v0.1.14
v0.1.15
v0.1.16
v0.1.17
v0.1.18
v0.1.19
v0.1.20
v0.1.21
v0.1.22
v0.1.23
v0.1.24
v0.1.25
v0.1.26
v0.1.27
v0.1.28
v0.1.29
v0.1.30
v0.1.31
v0.1.32
v0.1.33
v0.1.90
v0.1.91
v0.1.92
v0.1.93
v0.1.94
v0.1.95
v0.1.96

  • To use a specific version of node.

nvm use 12

  • Here is the command output.

root@ip-172-31-16-172:/home/ubuntu# nvm use 12
Now using node v12.22.7 (npm v6.14.15)

  • To find the default Node version.

nvm run default --version

  • Here is the command output.

root@ip-172-31-16-172:/home/ubuntu# nvm run default --version
Running node v17.0.0 (npm v8.1.0)
v17.0.0

Leave a Reply