Ubuntu

This guide has been tested on Ubuntu distributions 18.04, 20.04, and 22.04.

Run the following command to update:

apt-get -y update

Please wait for a while; this process may take 1-2 minutes. Once it's complete, you'll see a prompt for entering commands as a user.

Next, use the universal command to install OpenJDK 8:

sudo apt install -y openjdk-8-jdk

Wait for the download and installation of all files to finish.

Debian

Install the required packages:

apt install apt-transport-https gnupg wget software-properties-common -y

Add the repository:

wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | apt-key add -
add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/

Update the package list:

apt-get update

Install OpenJDK 8:

apt-get install adoptopenjdk-8-hotspot -y

Verification of Installation

java -version

Uninstalling Java

apt-get -y purge openjdk* java*