10

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
9

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.

| improve this answer | |
  • 6
    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
3

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
| improve this answer | |
2

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

Add following lines to there.

JAVA_HOME=/usr/lib/jvm/java-6-openjdk
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH
| improve this answer | |
  • 1
    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
  • 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! – Thorbjørn Ravn Andersen Jul 7 '12 at 21:26
1

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!

| improve this answer | |
  • 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.) – Eliah Kagan Jul 8 at 2:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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