Remove java 8 and install java 7 in Ubuntu

There are times when you need a specific version of Java to be installed instead of the latest version. The following post will brief on the steps required to remove Java 8 and install Java 7 in Ubuntu 16.04

Always use the latest version of Java as there are quite a lot of bug fixes and security vulnerability has been fixed.

Removing Java 8
Open Terminal and enter the following commands.

sudo update-alternatives –remove-all java
sudo update-alternatives –remove-all javac
sudo update-alternatives –remove-all javaws
sudo rm -rf /usr/lib/jvm/jdk1.8.0

Install Java 7
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

Since Java 7 is no longer available in their repository, you need to manually download it from Oracle site.

Once the JDK 7 tar (jdk-7u80-linux-x64.tar.gz) is downloaded. Paste it in the below location

Now run the following command
sudo apt-get install oracle-java7-installer

After installation you also need to update alternatives by running the following command.

sudo update-alternatives –install “/usr/bin/java” “java” “/usr/lib/jvm/java-7-oracle/jdk1.7.0_80/bin/java” 1
sudo update-alternatives –install “/usr/bin/javac” “javac” “/usr/lib/jvm/java-7-oracle/jdk1.7.0_80/bin/javac” 1
sudo update-alternatives –install “/usr/bin/javaws” “javaws” “/usr/lib/jvm/java-7-oracle/jdk1.7.0_80/bin/javaws” 1

Once the above steps are completed. Check the java version from terminal
javac -version
java -version

It should display jdk 1.7