Java command not found even after "sudo apt-get install openjdk-6-jdk"

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.


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.

JAVA_HOME=/usr/lib/jvm/java-6-openjdk
export JAVA_HOME
PATH=$PATH:$JAVA_HOME/bin
export PATH