Introduction
We are going to describe the steps to install the Oracle JRE for Java. Ubuntu repositories does not provide Oracle Java, instead it provides open-jdk. To solve this issue we will add the webupd8team repository to apt.
Step 1: Adding webupd8team repository to apt
We will use the command add-apt-repository for adding the webupd8team repository with thew following commands:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
Step 2: Install Java
Now we can install Java 6,7 or 8 check this package list:
- oracle-java6-installer
- oracle-java7-installer
- oracle-java8-installer
Choose one package and install it with
sudo apt-get install oracle-java8-installer
Step3: Select Oracle Java as the default JVM
Update: Optionally you can use the command sudo apt-get install oracle-java7-set-default to skip this step.
Now we are going to use update-alternatives command for selecting the java version we want to have as default:
sudo update-alternatives --config java
The output will be something like this:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-7-oracle/jre/bin/java 1062 auto mode
1 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1062 manual mode
Press enter to keep the current choice[*], or type selection number:
Choose the right number (in our output the number 2) and you are ready to use Oracle Java.
Check the output of this command to verify everything is correct.
java -version