- Open the terminal and log in as root. If you are logged in as another user, you will need to add sudo before each command.
- Working on a Linux Ubuntu 16.04 server
- No installations of previous Java versions
Install Oracle Java 8
Step 1: Update & Upgrade
It is advised to update your system by copy and pasting the command below. Be sure to accept the update by typing Y when asked to continue:
apt-get update && apt-get upgrade
Step 2: Install the Repository
WebUpd8 Team Personal Package Archive (PPA), a third party repository, allows us to download the package necessary for Java 8 installation. Press Enter to continue the installation.
Once again, update your package list.
Step 3: Install Java 8
Use the apt-get command to install Oracle’s Java 8 via their installer:
apt-get install oracle-java8-installer
Click Y to continue and press Enter to agree to the licensing agreement.
Select Yes and hit the Enter key.
Step 4: Verify Java 8 is Installed
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
Set Java’s Home Environment
It’s essential to know the path of our Java installation for our applications to function. Where is Java installed? Run this command to find its path:
update-alternatives --config java
~# update-alternatives --config java
There is 1 choice for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 auto mode
* 1 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode
Copy the highlighted path from the second row: /usr/lib/jvm/java-8-oracle/jre/bin/java/. After copying, open the file /etc/environment and add in the path of your Java installation to the end of your file.
Save the file by hitting ESC button and type :wq to execute the command below to recognize the changes to the file:
You should now see the path of installation when using the $Java_Home variable:
~# echo $JAVA_HOME