Step 1 – Install JAVA 8First of all, you need to add webupd8team Java PPA repository in your system. After that install, Oracle Java 8 using following a set of commands. The oracle-java8-installer package is not the actual Java package, it has a Java installation script which downloads Java archive from official java website and configures on your system.
sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt-get install oracle-java8-installer
Step 2 – Verify Installed Java VersionAfter successfully installing Oracle Java 8 using the above steps, Let’s verify the installed version using the following command.
java -version java version "1.8.0_161" Java(TM) SE Runtime Environment (build 1.8.0_161-b12) Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
Step 3 – Setup Java EnvironmentAlso, install Java configuration package. It seems like below package is already installed with latest operating systems during installation of JAVA packages. But you can still make sure by running below command.
sudo apt-get install oracle-java8-set-defaultNow add the JAVA_HOME and JRE_HOME environment variable in /etc/environment configuration file using the following command.
cat >> /etc/environment <<EOL JAVA_HOME=/usr/lib/jvm/java-8-oracle JRE_HOME=/usr/lib/jvm/java-8-oracle/jre EOL