In this tutorial we’ll learn how to install Java on Ubuntu 16.04. We will also install and configure its prerequisites. There are two standard types of installations, JRE (Java Runtime Environment) and JDK (Java Development Kit). Like the base model car, JRE enables the ability to create Java Applications for different types of deployments using minimal core tools to accomplish the task. JDK is a fully loaded Development Kit that has everything that JRE has plus additional resources to create/secure Applications and Applets.
I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an Ubuntu 16.04 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.
Install Java on Ubuntu 16.04
Step 1. First, ensure your system and apt package lists are fully up-to-date by running the following:
apt-get update -y && apt-get upgrade -y
Step 2. Installing Java.
Add the Webupd8 Team PPA repository, run the following commands on your server:
apt-get install software-properties-common apt-add-repository ppa:webupd8team/java
Run commands to update system package index and install Java installer script:
apt-get update apt-get install oracle-java8-installer
If you have multiple versions of Java installed on your server, then you have the ability to select a default version. Check your alternatives with the following command:
update-alternatives --config java
To check the Java version after installing the package, run command:
Step 3. Setup JAVA_HOME on Ubuntu 16.04.
The PPA also contains a package to automatically set Java environment variables, just run command:
apt-get install oracle-java8-set-default
Congratulation’s! You have successfully configured Java (JRE or JDK) on your Ubuntu 16.04 LTS server.