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.
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.
Click on the download link as highlighted in Fig 2. It will ask to accept the License Agreement as shown in Fig 3.
Open the terminal and make directory /
>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 /
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.
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:
# 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.
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).