You can install either OpenJDK or Oracle JDK.
Steps to install Java 8 on Ubuntu 16.04.
Installing OpenJDK on Ubuntu is very easy you just need to run the following command.
This command will both download and install the required packages.
If you want just the Java run time environment (JRE) then you can use the following command.
Installing Oracle JDK on Ubuntu
Script for installing Oracle JDK using apt-get is maintained by the third party, you can use that to install Oracle JDK or download the latest JDK from Oracle’s site and install it yourself.
Using apt-get
For installing using apt-get you need to add Oracle’s PPA (Personal Package Archive) then update the package repository using that information.
Use the following command to add PPA
Use the following command to update packages.
Then for installing Java 8 use the following command.
sudo apt-get install oracle-java8-installer
Manually downloading and installing Oracle JDK
You can download the required JDK version from here - http://www.oracle.com/technetwork/java/javase/downloads/index.html
Then create a directory where you want to unpack the downloaded tar ball.
Change directory to Downloads where tar ball will be downloaded by default and copy it to the created directory.
Then unpack the tar in the directory /usr/local/java using the following command.
Setting JAVA_HOME environment variable and path
You need to set the JAVA_HOME environment variable so that the applications know the Java installation location.
Open the /etc/environment file using gedit.
Add JAVA_HOME environment variable at the end of the file.
Also append the path to /bin directory of your Java installation to the existing PATH variable in /etc/environment file.
Save and close the file. You need to reload it so that the changes are visible.
source /etc/environment
If you echo JAVA_HOME now you should get the path you set, try that using the following command.
If you have any doubt or any suggestions kindly drop a comment. Thanks!
Steps to install Java 8 on Ubuntu 16.04.
Installing OpenJDK on Ubuntu is very easy you just need to run the following command.
sudo apt-get install openjdk-8-jdk
This command will both download and install the required packages.
If you want just the Java run time environment (JRE) then you can use the following command.
sudo apt-get install openjdk-8-jre
Installing Oracle JDK on Ubuntu
Script for installing Oracle JDK using apt-get is maintained by the third party, you can use that to install Oracle JDK or download the latest JDK from Oracle’s site and install it yourself.
Using apt-get
For installing using apt-get you need to add Oracle’s PPA (Personal Package Archive) then update the package repository using that information.
Use the following command to add PPA
sudo add-apt-repository ppa:webupd8team/java
Use the following command to update packages.
sudo apt-get update
Then for installing Java 8 use the following command.
sudo apt-get install oracle-java8-installer
Manually downloading and installing Oracle JDK
You can download the required JDK version from here - http://www.oracle.com/technetwork/java/javase/downloads/index.html
Then create a directory where you want to unpack the downloaded tar ball.
sudo mkdir /usr/local/java
Change directory to Downloads where tar ball will be downloaded by default and copy it to the created directory.
sudo cp -r jdk-8u151-linux-x64.tar.gz /usr/local/java
Then unpack the tar in the directory /usr/local/java using the following command.
sudo tar zxvf jdk-8u151-linux-x64.tar.gz
Setting JAVA_HOME environment variable and path
You need to set the JAVA_HOME environment variable so that the applications know the Java installation location.
Open the /etc/environment file using gedit.
sudo gedit /etc/environment
Add JAVA_HOME environment variable at the end of the file.
JAVA_HOME="/usr/local/java/jdk1.8.0_151"
Also append the path to /bin directory of your Java installation to the existing PATH variable in /etc/environment file.
:/usr/local/java/jdk1.8.0_151/bin
Save and close the file. You need to reload it so that the changes are visible.
source /etc/environment
If you echo JAVA_HOME now you should get the path you set, try that using the following command.
echo $JAVA_HOME
If you have any doubt or any suggestions kindly drop a comment. Thanks!