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

Follow the instruction to setup Java on Ubuntu 11.10 from How do I install Java?.

Running following command to install:

sudo apt-get install openjdk-6-jdk

After it succeeded and I typed "java", it prompts me with this error:

The program 'java' can be found in the following packages:
 * gcj-4.4-jre-headless
 * gcj-4.6-jre-headless
 * openjdk-6-jre-headless
 * gcj-4.5-jre-headless
 * openjdk-7-jre-headless
share|improve this question
reboot. still can't be found. thanks – TonyMocha Mar 6 '12 at 6:32
Rebooting is nearly never a solution on Linux. If it is, a much shorter solution would have helped too, normally, like restarting a program or a fresh login. – user unknown Jul 7 '12 at 16:02

Did you try this command?

sudo update-alternatives --config java

This will list all the Java versions installed and configured.

If you see one or more installs, it will give you a list each element starting with a number. Just choose the number that corresponds to the version you want to use by default.

If you don't see any installed then something is not right. In that case take a look at this question.

While that question is for Oracle Java 7, it lists methods common to both Java 6 and Java 7, for installing Java and getting Ubuntu to see and link to the new Java installation. If you want version 6, just download the version 6 JDK and follow the instructions provided in that question, changing the filename accordingly.

share|improve this answer
If when running update-alternatives, you get a message like update-alternatives: warning: /etc/alternatives/java is dangling, delete the dangling link (i.e. sudo rm /etc/alternatives/java) and run update-alternatives again. – Mark Dec 18 '13 at 14:45
up vote 2 down vote accepted

Solved this by manually setting java path with /etc/profile.

Add following lines to there.

export JAVA_HOME
export PATH
share|improve this answer
You did not fix the broken package installation, you digged in and found the bin folder and put it first in your path. – Thorbjørn Ravn Andersen Jun 26 '12 at 7:48
@ThorbjørnRavnAndersen: Which broken package installation? – user unknown Jul 7 '12 at 16:04
@userunknown If the sudo ...command did not result in a javacommand being present in $PATH, the package installation did not complete correctly and hence is broken! – Thorbjørn Ravn Andersen Jul 7 '12 at 21:26

Install Oracle Java by following commands

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
share|improve this answer

You can fix such types of problem by installing the selected packages:

sudo apt-get install gcj-4.4-jre-headless
sudo apt-get install gcj-4.6-jre-headless
sudo apt-get install openjdk-6-jre-headless
sudo apt-get install gcj-4.5-jre-headless
sudo apt-get install openjdk-7-jre-headless

sudo java -version

I think it works now!

share|improve this answer
openjdk 6 and 7 can't be installed at the same time, can they? – Mark Paskal Oct 21 '12 at 1:51

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.