It provides all the steps required to install Java 8 on Ubuntu 18.04 LTS.

How To Install Java 8 On Ubuntu
How To Install Java 8 On Ubuntu
September 08, 2019

In this post, we will discuss all the steps required to install Java 8 distributed by Oracle on the popular Linux distribution i.e. Ubuntu. It includes the steps for Ubuntu 18.04 LTS. The steps should be similar to other releases of Java, Ubuntu and other flavors of Linux.

Notes: Make sure that you have gone through the License Agreement for JDK 8 released after April 16, 2019.

Download JDK

Open the browser and search for Download JDK 8. It will show the JDK download page with the change in the licensing model as shown in Fig 1 and Fig 2.

Oracle JDK License Changes

Fig 1

Oracle JDK Download

Fig 2

Click on the download link as highlighted in Fig 2. It will ask to accept the License Agreement as shown in Fig 3.

Oracle JDK License Agrement

Fig 3

Install Java

Open the terminal and make directory /usr/java to keep java installations. We can install multiple versions of Java in this directory. Now copy the downloaded file to this location and extract it as shown below:

>sudo mkdir /usr/java
>cd /usr/java
>sudo cp /mydrive/setups/ubuntu/java/jdk/jdk-8u221-linux-x64.tar.gz jdk-8u221-linux-x64.tar.gz
>sudo tar -xzvf jdk-8u221-linux-x64.tar.gz

The above steps will install JDK to the path /usr/java/jdk1.8.0_221

Set Environment Variables

In this step, we will configure the environment variable to use the JDK installed by us via the command line.

>sudo nano /etc/profile

Scroll down by pressing Page Down button and add at the end of this file:

# Java 8
JAVA_HOME=/usr/java/jdk1.8.0_221 PATH=$PATH:$HOME/bin:$JAVA_HOME/bin export JAVA_HOME export JRE_HOME export PATH

Now press Ctrl + O and press Enter to write our change. Press Ctrl + X to exit the nano editor. The nano editor should look like the one shown in Fig. 4.

Oracle JDK Path

Fig 4

Configure Java Commands

Now we need to configure Java commands to newly-installed JDK. We can check the installed Java before and after executing these commands as shown below:

>java -version

# Optional - Uninstall Java - If java is already installed on the system
>ls -l /etc/alternatives
# Remove existing alternative of - java, javac, javaws
# I have removed java and javac in my case
>sudo update-alternatives --remove "java" "/usr/java/jdk-12.0.2/bin/java"
>sudo update-alternatives --remove "javac" "/usr/java/jdk-12.0.2/bin/javac"
>sudo update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk1.8.0_221/bin/java" 1 >sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/jdk1.8.0_221/bin/javac" 1 >sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/java/jdk1.8.0_221/bin/javaws" 1 >java -version

The output of these commands is displayed in Fig. 5.

Oracle JDK Install

Fig 5

You might need to uninstall existing Java in order to install Java 8. In my case, as shown in Fig 5, I needed to uninstall OpenJDK 12.

This is how we can install Java distribution from Oracle on Ubuntu 18.04 (Bionic Beaver).

Write a Comment

Click on the captcha image to get new code.
Discussion Forum by DISQUS