user411103
user411103

Reputation:

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?

Upvotes: 24

Views: 89400

Answers (9)

Ronak
Ronak

Reputation: 1

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

Upvotes: 0

Asanka Sampath
Asanka Sampath

Reputation: 583

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

Upvotes: 0

Jose Mhlanga
Jose Mhlanga

Reputation: 855

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}"

Upvotes: 0

Sai prateek
Sai prateek

Reputation: 11896

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"

Upvotes: 6

Sandeepraj Singh
Sandeepraj Singh

Reputation: 109

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.

Upvotes: 6

Mashmoom
Mashmoom

Reputation: 497

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.

Upvotes: 0

Shubham
Shubham

Reputation: 101

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

Upvotes: 4

Let'sRefactor
Let'sRefactor

Reputation: 3346

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.

Upvotes: 37

Bharath Teja
Bharath Teja

Reputation: 101

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

Upvotes: 0

Related Questions