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 want to start toying around with java (eventually getting to the point where I can write basic little programs for android or web), but I've managed to have java messed up on my computer (from past experiments).

I'm not sure which version of java I have, and would like to know if there is a command to see the version of java that is installed and active. Also, which version works best? All this on 32bit Ubuntu 12.04

Ok, so it seems like I have both openjdk 6 and 7, with openjdk 7 in use. I want to use openjdk 7, so how do I uninstall openjdk 6? Is just via USC good enough or is there a command that should be run?

share|improve this question
up vote 29 down vote accepted

This command should tell you what is currently providing the Java virtual machine (java) and the Java compiler (javac):

file /etc/alternatives/java /etc/alternatives/javac

This assumes the "alternatives" system is working properly, which might not be the case, depending on how Java has been "messed up" in the past. To check this, run:

file `which java javac`

If the alternatives system is working correctly and being used by Java, then you should see:

/usr/bin/java:  symbolic link to `/etc/alternatives/java'
/usr/bin/javac: symbolic link to `/etc/alternatives/javac'

Otherwise please edit your question to provide details. Then it should be possible to give a more specific answer.

You can remove openjdk-6 with the Software Center. There are multiple packages associated with it, so you may need to remove more than one packages. (All the `openjdk-6 packages are listed here.)

Or you can use the command-line:

sudo apt-get remove openjdk-6-\* icedtea-6-\*

However, whichever method you use, you may want to check first to see what depends on these packages--you might have software installed that specifically needs version 6. (Probably not, but possibly.)

You can check for this by simulating the removal operation on the command-line:

apt-get -s remove openjdk-6-\* icedtea-6-\*

This will show you the effects of removing those packages, including what other packages would be removed as well. (You'll notice that since this is a simulation, you don't need sudo.)

If you want to be able to continue using Java content online in your web browser (this is not the same thing as JavaScript), then before you remove any icedtea-6- or openjdk-6- packages (except perhaps openjdk-6-jdk), you should make sure you have icedtea-7- packages installed corresponding to whatever icedtea-6- packages are installed.

share|improve this answer

The simplest way is:

update-java-alternatives -l - Shows you all the Java versions you have installed.

java -showversion - Shows you the java version you are using and help.

java -version - Java Version only

Normally it would be OpenJDK.

share|improve this answer


java -version
javac -version

These commands display what version of java (the interpreter that runs Java programs) and javac (the compiler that creates them) you have installed.

See the image above for details.

share|improve this answer

This what I did that worked for me :

Open your terminal :

control + alt + T

Then type ( or copy and paste from here ) these commands one at a time:

sudo rm /var/lib/dpkg/info/oracle-java7-installer*
sudo apt-get purge oracle-java7-installer*
sudo rm /etc/apt/sources.list.d/*java*
sudo apt-get update
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer

Then to be on the safe side, I would reboot.

To find your java version type

java -version

and you should see output similar to this:

java version "1.7.0_04"
Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)

Although yours will be in 32 bits.

I highly suggest using Java 7, but the updates will try to install Java 6 too. That is OK. But your default should still come up as 7. Everything I have thrown at it works as long as your video card drivers work.

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.