Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I had installed sun-java, but I want to revert back to OpenJDK 7. I was trying to re-install from the terminal using the command sudo apt-get install openjdk-7-jre, same from Synaptic and Software Center, but it does not work.

I try to use the command java -version and then I get a message like The java program can be found on follow packages» open-7-jre-headless

So, I tried to install it, but they ARE installed on my system...

I do no want format my PC just for Java.


share|improve this question
What do you mean "does not work"? Can you add the output of apt-get install openjdk-7-jre to your question? – Iain Lane Jan 10 '12 at 20:58



to switch between different implementations without removing or reinstalling and downloading packages.

share|improve this answer

In order to switch between installed Java versions, you can use the update alternatives command.

  • To obtain a list of the installed Java packages on a system, run the following command from the terminal(Ctrl-Alt-t):

    sudo update-alternatives --config java

    This will give a list output similar to the following:

    There are 4 choices for the alternative java (providing /usr/bin/java).
       Selection    Path                                           Priority   Status
      0            /usr/lib/jvm/java-7-oracle/jre/bin/java         1070      auto mode
      1            /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java   1051      manual mode
    * 2            /usr/lib/jvm/java-7-oracle/jre/bin/java         1069      manual mode
    Press enter to keep the current choice[*], or type selection number: 

In this particular case, the Oracle Java 7 version is the current default(indicated by the asterisk).

In order to switch to the OpenJDK version, you would select option 1 at the prompt and press the Enter key.

You will now be running the OpenJDK 7 version.

No other changes will be needed to switch your Java versions.

share|improve this answer

If you want to eliminate Sun Java altogether...

You can use dpkg-query -l *sun-java* to see the sun-java related packages that are installed. You can use sudo apt-get purge sun-java, etc., with the names of the package(s) to get rid of them.

If OpenJDK is already installed, that's great, hopefully it'll just work from there. If not, sudo apt-get update && sudo apt-get update might get you figured out.

If it still doesn't work, try repeating the package removal/purging process above for OpenJDK and re-installing it to start from scratch.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.