I followed the instruction to set up Java on Ubuntu 11.10 from How do I install Java?.

I ran this command to install:

sudo apt-get install openjdk-6-jdk

After it succeeded and I typed java, I got 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

4 Answers 4


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.

  • 7
    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, 2013 at 14:45

Note: WebUpd8 team's PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn't have any Java files. More information can be found on PPA's page on Launchpad. Hence this method no longer works and exists because of historical reasons.

Install Oracle Java using the following commands

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

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

Add following lines to there.

export JAVA_HOME
export PATH
  • 1
    You did not fix the broken package installation, you digged in and found the bin folder and put it first in your path. Jun 26, 2012 at 7:48
  • @ThorbjørnRavnAndersen: Which broken package installation? Jul 7, 2012 at 16:04
  • 1
    @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! Jul 7, 2012 at 21:26

There is a default java that you can set up by running one of the following commands, depending on your needs:

sudo apt install default-jre            
sudo apt install openjdk-11-jre-headless
sudo apt install openjdk-8-jre-headless 

Let me know if it works!

  • 2
    It's a bit strange to run all of these commands, since each one is by itself sufficient to install a JRE, and most of the time people just want one JRE. (Also, the JRE that the first one installs may be the same as one of the others.) Jul 8, 2020 at 2:44
  • this answer isn't valid as it just suggests things to do instead of giving a clear and definite answer. Also the person wants the JDK and not the JRE. Dec 25, 2020 at 11:25

You must log in to answer this question.

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