Search code examples
javaubuntujava-home

JAVA_HOME is not defined correctly on Ubuntu?


I am trying to install some software (Shibboleth) in Ubuntu 14.04. I already have Java 7 OpenJDK installed in /usr/lib/jvm/, and I have these lines in /usr/environment

JAVA_HOME="/usr/lib/jvm/java-7-openjdk-amd64"
export JAVA_HOME

If I type echo $JAVA_HOME I correctly get /usr/lib/jvm/java-7-openjdk-amd64. However, when I try to install Shibboleth I always get Error: JAVA_HOME is not defined correctly. Cannot execute java.

Interestingly, if I type java command it works (it refers to /usr/lib/java which is a link to the right one). However, when I try to run bash bin/install.sh of Shibboleth, I get the JAVA_HOME error

I already tried setting JAVA_HOME to the jre folder with same result. Any ideas?


Solution

  • Add both JAVA_HOME & PATH to your ~/.profile

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

    And, add following to your /etc/profile.d/java.sh

    JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
    export JAVA_HOME
    PATH=${JAVA_HOME}/bin:${PATH}
    export PATH
    JRE_HOME=/usr/lib/jvm/jre
    export JRE_HOME
    JAVA_OPTS="-XX:+AggressiveOpts -Xms256m -Xmx512m -XX:MaxPermSize=256m -XX:+DisableExplicitGC"
    export JAVA_OPTS
    

    For more info, Refer Documentation

    Hope it helps.