Installing Java on Ubuntu 18.04/16

There are two standard types of installation available are JDK and JRE. JDK (Java Development Kit) provides the ability to develop a new Java application, which includes Java compiler. JRE (Java Runtime Environment) provides the runtime environment for any Java application with applets. The Java developers required to install JDK and JRE both on their system to create new Java Applications.
IMPORTANT: The Oracle Java 8 is no longer available to download publically. You can use below link to install Java 11. You may also continue to this tutorial to install OpenJDK 8.
Use this tutorial to install OpenJDK Java 8 on Ubuntu 19.10, 18.04 LTS, 16.04 LTS, LinuxMint 19, 18 using PPA. Follow the below steps to install Java 8 on Ubuntu via the command line.

Step 1 – Install Java 8 on Ubuntu

The OpenJDK 8 is available under default Apt repositories. You can simply install Java 8 on an Ubuntu system using the following commands.
Run below commands to install Java 8 on Ubuntu and LinuxMint.
sudo apt update
sudo apt install openjdk-8-jdk openjdk-8-jre

Step 2 – Verify Java Inatallation

After successfully installing Oracle Java 8 using the above steps, Let’s verify the installed version using the following command.
java -version

openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

Step 3 – Setup JAVA_HOME and JRE_HOME Variable

After installing Java on Linux system, You must have to set JAVA_HOME and JRE_HOME environment variables, which is used by many Java applications to find Java libraries during runtime. You can set these variables in /etc/environment file using the following command.
cat >> /etc/environment <
All done, you have successfully installed Java 8 on a Linux system. You may also need to install Tomcat server to run your Java web application. Use our another tutorial to Install Tomcat 7 or Install Tomcat 8 or Install Tomcat 9 on Ubuntu, Debian, and LinuxMint systems.