简体   繁体   中英

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 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?

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, ReferDocumentation

Hope it helps.

Instead of

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

I did

EXPORT JAVA_HOME='/usr/lib/jvm/java-1.7.0-openjdk-amd64'

Works.

from Ubantu terminal execute:

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

to test maven run:

mvn --version

it will give output:

Maven home: /usr/share/maven
Java version: 1.7.x.xxx, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-7-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-47-generic", arch: "amd64", family: "unix"

According to Your editor.

sudo vim /etc/profile

add these 2 lines at the end of the file

export JAVA_HOME="/usr/lib/jvm/java-8-oracle"  
export PATH=JAVA_HOME/bin:$PATH

Then

source /etc/profile

Check

mvn -version

you should set the path to bin folder where java, javac files are found. In your case it might be /usr/lib/jvm/java-7-openjdk-amd64/bin

I issue is that the install.sh script which you are running has the java path wrong.

Edit the file using nano

    sudo nano idp-install.sh

or vim editor

    vim idp-install.sh

and change the line which corresponds to java path and add the correct java path. This will solve your problem.

PS This solution is specific to the java path for Shibboleth installation.

For future comers, please note this problem usually happens because Java is not properly set in your environment. Take the following steps to fix the problem

first, check where your JDK is using the following command cd /usr/lib/jvm/{jdk-version} Now that you have the full path where your JDK is, copy the whole path like so, in my case I have jdk1.8.0_261

So you copy /usr/lib/jvm/jdk1.8.0_261 path, open /etc/environment and set the JDK path properly as follows

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:usr/lib/jvm/jdk1.8.0_261:/opt/apache-maven-3.6>
JAVA_HOME=/usr/lib/jvm/jdk1.8.0_261
M2_HOME="/opt/apache-maven-3.6.3"

Note that I have added the /usr/lib/jvm/jdk1.8.0_261 to the PATH variable and also to the JAVA_HOME variable,

This should resolve the error Error: JAVA_HOME is not defined correctly. Cannot execute java Error: JAVA_HOME is not defined correctly. Cannot execute java since the JDK is now properly set in the PATH and in the JAVA_HOME , then for the Shibboleth you can also now define the path where it is installed like so (This is an example- don't know how to set Shibboleth)

SHIBBOLETH_HOME="/opt/shibboleth-{version}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM