Ubuntu installs the Gnu JVM in /usr/bin/java. This VM is incompatible with the Eclipse IDE. To get Eclipse to run on Ubuntu, install Sun's JDK somewhere on your system (/opt/java/jdk1.5.0, for example). Ensure that the directory containing Sun's JVM is before /usr/bin/java in your PATH. Eclipse will now pick up the Sun JVM and work fine.

Below are some BASH aliases to manage the path and switch between JVM versions. Add them to your .bash_aliases file. You can then type "jdk" to show the currently active JDK version, "jdk version" to switch to a specific version of the JDK and "jdks" to list all the installed JDKs. JDKs need to be installed under /opt/java. I usually create symlinks in /opt/java to give convenient names to the JDKs because the installers create directories that include the patch number. E.g. I'd symlink /opt/java/jdk1.5.0 -> /opt/java/jdk1.5.0_06 and /opt/java/jdk1.4.2 -> /opt/java/jdk1.4.2_10, etc.

function jdks() {
    ls -d /opt/java/jdk* | cut -c 14-
}

function jdk() {
    if (( $# == 0 )) 
    then
        if [ -z $JAVA_HOME ]
        then
            echo "no JDK configured" > /dev/stderr
            false
        else
            echo $JAVA_HOME | cut -c 14-
        fi
    else
        if [ -d /opt/java/jdk$1 ]
        then
            local old_java_home=$JAVA_HOME
            export JAVA_HOME=/opt/java/jdk$1
            
            if [ -z $old_java_home ]
            then
                PATH=$JAVA_HOME/bin:$PATH
            else
                PATH=${PATH/:$old_java_home\/bin/:$JAVA_HOME\/bin}
            fi
        else
            echo "JDK $1 not installed; available JDKs:" > /dev/stderr
            jdks > /dev/stderr
        fi
    fi
}

HowToRunEclipseOnUbuntuLinux (last edited 2008-01-03 17:40:15 by localhost)