Next, we’ll remove each symlink to a Java binary from the Debian alternatives system. I have split the following commands onto multiple lines to ensure that they display correctly on this page. However, you can remove the \ and then type each command on one line in the terminal.

You should no longer see 1.7.0 u04 for the version of any of the above commands.

IMPORTANT WARNINGYou must type the next 2 commands perfectly to avoid permanently destroying your system. If you do this wrong, you could delete important system files, including those that are required by Ubuntu.

cd /usr/lib/jvm

sudo rm -rf jdk1.7.0_04

sudo update-alternatives --config java

Output:
update-alternatives: error: no alternatives for java.

sudo update-alternatives --config javac

Output:
update-alternatives: error: no alternatives for javac.

sudo update-alternatives --config javaws

Output:
update-alternatives: error: no alternatives for javaws.

sudo vi /etc/environment

Delete the line with JAVA_HOME

Uninstall OpenJDK (if installed)

First we’ll check which OpenJDK packages are installed.

sudo dpkg --list | grep -i jdk

Next, let’s uninstall OpenJDK related packages. Edit the list of packages below if you have additional or different OpenJDK packages installed.