Install Oracle Java in Ubuntu by PPA
This provides instructions on how to install the Oracle Java JDK (which includes Java JDK, JRE and the Java browser plugin). The PPA provides the full Oracle JDK package.
To add the PPA and install Oracle Java 7 in Ubuntu use this:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
To add the PPA and install Oracle Java 8 in Ubuntu use this:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
If you want to see your version of java run the following command in the terminal:
java -version
It should return something like this
Java version "1.7.0_51" (version 7) or "1.8.0" (version 8)
Java(TM) SE Runtime Environment (build 1.7.0_51-b13) - version 7
Java(TM) SE Runtime Environment (build 1.8.0-b132) - version 8
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode) - version 7
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode) - version 8
If the Java version in use is not 1.7.0, you can try to run the following command in the terminal:
sudo update-java-alternatives -s java-7-oracle
The installer requires you accept the Oracle license before the installation begins. This is only required once. If you need the installation to be automated, you can run the following command to automatically accept the Oracle license:
Version 7
echo oracle-java7-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
Version 8
echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | sudo /usr/bin/debconf-set-selections
Setting Java environment variables To automatically set up the Java 7 environment variables, you can install the following package:
sudo apt-get install oracle-java7-set-default
If you've already installed oracle-java6-set-default or oracle-java8-set-default, they will be automatically removed when installing oracle-java7-set-default (and the environment variables will be set for Oracle Java 7 instead). Switch back and forth between Java 7 and 8
Switch to Java 7
sudo update-java-alternatives -s java-7-oracle
And, switch back to Oracle Java 8 using:
sudo update-java-alternatives -s java-8-oracle
If you get some warnings when running these two commands, ignore them.
How to Remove Oracle Java To remove java on your system and want to go back to OpenJDK or remove java completely, all you have to do is remove the Oracle JDK7 Installer and the previous Java (OpenJDK, etc.) version will be used:
sudo apt-get remove oracle-java7-installer
sudo apt-get remove oracle-java8-installer
Special thanks to webupd8.org for their great tutorial for which this is based.