JAVA_HOME is not defined correctly on Ubuntu?
Asked Answered
S

9

22

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?

Soekarno answered 23/1, 2016 at 17:40 Comment(2)
First install necessary packages apt-get install openjdk-7-jre-headless apt-get install tomcat7 and see.Laniary
I already have both of them installedSoekarno
P
36

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.

Pharmacy answered 23/1, 2016 at 17:56 Comment(6)
I tried this but same error. Interestingly, if I type "java" command it works. However, when I try to run "bash bin/install.sh" of Shibboleth, I get the JAVA_HOME error.Soekarno
Updated my answer, hope it helps nowBathe
Still same error. Is it OK that all these variables are defined without quotes? I didn't even had a .bash_profile or /etc/profile.d/java.sh filesSoekarno
Ubuntu use ~/.profile instead of ~/.bash_profile, updated my answerBathe
/etc/profile.d/java.sh you need to create one, use cat.Bathe
For some apps such as PDFsam: ~/.bashrc with jdk version 11.Aeriel
L
6

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.

Laveen answered 8/3, 2019 at 21:3 Comment(1)
In my case using single quotes worked!Endoplasm
T
6

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"
Transilluminate answered 31/5, 2019 at 10:6 Comment(0)
W
4

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
Whitethorn answered 5/10, 2018 at 7:15 Comment(0)
G
0

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

Grieco answered 23/1, 2016 at 17:48 Comment(1)
Already tried, same result. Please, note that I can run the command "java" properly. The error is displayed when I try to run bin/install.sh on Shibboleth.Soekarno
S
0

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.

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

Statuary answered 20/11, 2018 at 13:41 Comment(0)
B
0

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 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}"
Blesbok answered 28/9, 2020 at 7:54 Comment(0)
E
0

export JAVA_HOME='/usr/lib/jvm/java-11-openjdk-amd64'

Exasperate answered 2/5, 2023 at 5:22 Comment(0)
P
0

For ubantu :

To correct JAVA_HOME variable

step 1 : Open the /etc/environment file in a text editor with sudo privileges. You can use the following command:

    **command : sudo nano /etc/environment**

step 2 : correct the variable

JAVA_HOME="/lib/jvm/java-11-openjdk-amd64"

step 3 : press ctrl+o

step 4 : click on Enter

step 5 : press ctrl+x

Done now try your work

all the best

Photodynamics answered 8/2 at 9:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.