34

I installed oracle java 8 by typing in terminal:

sudo add-apt-repository ppa:webupd8team/java  
sudo apt-get update
sudo apt-get install oracle-java8-installer

but now I want to uninstall oracle java 8 and install oracle java 7 instead with sudo apt-get install oracle-java7-installer

how can I uninstall java 8? which commands should I type in terminal?

4 Answers 4

23

Try with this code in terminal to remove java 8:

sudo apt-get purge oracle-java8-installer

Then type:

javac -version

The output should be:

javac: command not found

and to install java 7 in Ubuntu I use this code in terminal:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

After that type the following to see if there is java installed:

java -version

The output should be:

java version "1.7.0_80"
2
  • 1
    This doesn't work, because the installer is, an installer. It does other things....
    – dorien
    Sep 21, 2015 at 14:53
  • 5
    It does remove java when the package is purged.
    – AndreKR
    Jul 24, 2017 at 17:25
6

First, you should not need to uninstall Java 8 to switch to Java 7, due to the alternatives system. Merely installing oracle-java7-installer will make Java 7 the preferred JVM/JDK. If you ever do need Java 8:

$ sudo update-java-alternatives --set java-8-oracle

Note that this changes /usr/bin/java, thus affecting everything on that system that relies on the default java. You may want to set JAVA_HOME (to, e.g., /usr/lib/jvm/java-8-oracle) if there is a single app that needs a different java.

WARNING: This works only for Oracle Java installed via webupd8 packages! Adding any OpenJDK package has undefined results!

If you really do need to get rid of Java8, the removal scripts for oracle-java8-installer will remove the JDK as well as the installer.

5

You can remove packages with aptitude by entering apt-get --purge remove <package> into a terminal.

I recommended the --purge option since apt-get remove may sometimes leave behind configuration files and those may cause conflicts if your plan is to install an older version.

1

I am guessing that most of it lives here:

$ du -h -d 1 /usr/lib/jvm
363M    /usr/lib/jvm/java-8-oracle

Using which and then ls -l on the result, I found that there is a chain of links that point all the way to the above folder, for various java executables (java, javac, etc.), so you might want to delete/unlink these as well.

$ which java
/usr/bin/java
$ ls -l /usr/bin/java
lrwxrwxrwx 1 root root 22 Apr  5  2015 /usr/bin/java -> /etc/alternatives/java
$ ls -l /etc/alternatives/java
lrwxrwxrwx 1 root root 39 May  3  2015 /etc/alternatives/java -> /usr/lib/jvm/java-8-oracle/jre/bin/java

There also seems to be some documentation in /usr/share/doc/java-common/ and user preferences in ~/.java

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .