Install Oracle Java 8 (Ubuntu)

Summary of what you are going to install:

  1. Java 8

It is always preferable to install programs via apt.

The recommended steps are the following:

Step 1 – Check if and which version is already installed

With the following command you can check if java is installed:

$ which java

If no Java is installed nothing will be outputted.

If a Java version is installed then the path to java binary will appear. If so, you can check which version is installed with the following command:

$ java -version

If you see Java 1.8 then Java 8 is already installed and you don’t have to do anything. If another version is installed you may uninstall it if you wish. If a OpenJDK  version is installed then it is recommended to uninstall it if there is no specific reason you needed it.

Step 2 – Uninstall OpenJava is needed

If OpenJava is installed, uninstall it via the following command:

$ sudo apt-get purge openjdk*

If and only if the above command fails you could try the following set of commands.

# uninstall OpenJDK
dpkg-query -W -f='${binary:Package}\n' | grep -E -e '^(ia32-)?(sun|oracle)-java' -e '^openjdk-' -e '^icedtea' -e '^(default|gcj)-j(re|dk)' -e '^gcj-(.*)-j(re|dk)' -e '^java-common' | xargs sudo apt-get -y remove
sudo apt-get -y autoremove
dpkg -l | grep ^rc | awk '{print($2)}' | xargs sudo apt-get -y purge
sudo bash -c 'ls -d /home/*/.java' | xargs sudo rm -rf
sudo rm -rf /usr/lib/jvm/*
for g in ControlPanel java java_vm javaws jcontrol jexec keytool mozilla-javaplugin.so orbd pack200 policytool rmid rmiregistry servertool tnameserv unpack200 appletviewer apt extcheck HtmlConverter idlj jar jarsigner javac javadoc javah javap jconsole jdb jhat jinfo jmap jps jrunscript jsadebugd jstack jstat jstatd native2ascii rmic schemagen serialver wsgen wsimport xjc xulrunner-1.9-javaplugin.so; do sudo update-alternatives --remove-all $g; done
sudo updatedb
sudo locate -b '\pack200'

Step 3 – Install Java 8

To install Java 8, use the following commands:

# Oracle Java
# - add official repository
# - install java via java installer
# - verify version
# - set java 8 as default
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get -q -y install oracle-java8-installer
$ java -version
$ sudo apt-get -q -y install oracle-java8-set-default

Step 4 – Configure which Java you want to run as default

To select the default java for your system, run the following command:

$ sudo update-alternatives –config java

 

 

References:

 

Leave a Reply