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.
Click on the download link as highlighted in Fig 2. It will ask to accept the License Agreement as shown in Fig 3.
Install Java
Open the terminal and make directory /
>sudo mkdir -p /usr/java/oracle >cd /usr/java/oracle >sudo cp /data/setups/jdk-8u241-linux-x64.tar.gz jdk-8u241-linux-x64.tar.gz >sudo tar -xzvf jdk-8u241-linux-x64.tar.gz
The above steps will install JDK to the path /usr/java/oracle/jdk1.8.0_241.
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/oracle/jdk1.8.0_241 PATH=$PATH:$HOME/bin:$JAVA_HOME/bin export JAVA_HOME export PATH
Now press Ctrl + O and hit 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
We can configure the Java commands to use the newly installed JDK by default. We can check the installed Java before and after executing these commands as shown below:
# Check version java -version
# Configure Java Alternatives sudo update-alternatives --install "/usr/bin/java" "java" "/usr/java/oracle/jdk1.8.0_241/bin/java" 1
# Configure Javac Alternatives sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/java/oracle/jdk1.8.0_241/bin/javac" 1
# Configure Java WS Alternatives sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/java/oracle/jdk1.8.0_241/bin/javaws" 1
# Check version java -version
# Use only in case of multiple JDKs installed # Configure Java sudo update-alternatives --config java
# Configure Java Compiler sudo update-alternatives --config javac
The output of these commands is displayed in Fig. 5. You might be required to switch among the installed JDKs in case of multiple installations.
This is how we can install Java 8 distribution from Oracle on Ubuntu 18.04 (Bionic Beaver).