Step 1: Install Node.js using NodeSource PPA / NVM
You can install Node.js 16 on Ubuntu 22.04|20.04|18.04 from either:
- NodeSource PPA Repository
- Using NVM Manager
Method 1) Install Node.js 16 on Ubuntu from NodeSource PPA Repository
To install any version of Node.js you can use a PPA (personal package archive) which is maintained by Nodesource. These PPAs have a lot more versions of Nodejs as compared to the official Ubuntu repositories. First, we will need to install the PPA in order to install Node.js 16. From your home directory, use the cURL command. Install cURL in case you haven’t installed it using sudo apt install curl
.
cd ~
curl -sL https://deb.nodesource.com/setup_16.x | sudo bash -
This command creates APT sources list for Nodesource Nodejs 16 repo which can be viewed as below.
# sample on Ubuntu 20.04
$ cat /etc/apt/sources.list.d/nodesource.list
deb https://deb.nodesource.com/node_16.x focal main
deb-src https://deb.nodesource.com/node_16.x focal main
With the repository added successfully, you can now install Node.js 16 on Ubuntu 22.04/20.04/18.04 with the command:
sudo apt -y install nodejs
Once installed, verify the version of Node.js.
$ node -v