How to Install Node.js on Ubuntu 20.04 LTS.

Login to the Ubuntu 20.04 server.

Install stable nodejs from Ubuntu respository by running the following command.

apt install nodejs

Output:

root@vps:~# apt install nodejs
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
    libc-ares2 libnode64 nodejs-doc
Suggested packages:
    npm
The following NEW packages will be installed:
    libc-ares2 libnode64 nodejs nodejs-doc

Then check the version of the nodejs once installation is done.

node --version

Output:

root@vps:~# node --version
v10.19.0

Installing different version of Node.js from source.

Install NVM manager by using "wget".

wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash

Output:

root@vps:~# wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
=> Downloading nvm from git to '/root/.nvm'
=> Cloning into '/root/.nvm'...
remote: Enumerating objects: 264, done.
remote: Counting objects: 100% (264/264), done.
remote: Compressing objects: 100% (230/230), done.
remote: Total 264 (delta 31), reused 100 (delta 24), pack-reused 0
Receiving objects: 100% (264/264), 116.38 KiB | 5.29 MiB/s, done.
Resolving deltas: 100% (31/31), done.

Update your shell ~/.profile by running following command

source ~/.profile

Next, Check the if NVM installed or not by checking for its version.

nvm --version

Output:

root@vps:~# nvm --version
0.33.8

List out the all available Node.js versions. you can see all Node.js versions from the first version to latest version.

nvm ls-remote

Output:

root@vps:~# nvm ls-remote
        v0.1.14
        v0.1.15
        v0.1.16
        ....
        v13.12.0
        v13.13.0
        v13.14.0
        v14.0.0
        v14.1.0

Now install Node.js with the version you want by running "nvm install" command.

eg: Here v14.1.0

nvm install 14.1.0

Output:

root@vps:~# nvm install 14.1.0
Downloading and installing node v14.1.0...
Downloading https://nodejs.org/dist/v14.1.0/node-v14.1.0-linux-x64.tar.xz...
######################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v14.1.0 (npm v6.14.4)
Creating default alias: default -> 14.1.0 (-> v14.1.0)

And check the version of the nodejs once installation is done.

node -v

Output:

root@vps:~# node -v
v14.1.0

Done!