Setting JAVA HOME in linux

0 votes

I am trying to set path for JAVA_HOME in my linux machine. When I run java -version it shows:

  • java version "1.7.0_55"
  • OpenJDK Runtime Environment (rhel-2.4.7.1.el6_5-x86_64 u55-b13)
  • OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)

I'm trying to build my maven project, but this comes up:

Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/java/jdk1.7.0_05/bin/java

Please tell what to do here. I am lost.

May 24, 2019 in Linux Administration by shubham
• 7,340 points
78,036 views

3 answers to this question.

0 votes
  1. find /usr/lib/jvm/java-1.x.x-openjdk
  2. vim /etc/profile

    Prepend sudo if logged in as not-privileged user, ie. sudo vim

  3. Press 'i' to get in insert mode
  4. add:

    export JAVA_HOME="path that you found"
    
    export PATH=$JAVA_HOME/bin:$PATH
  5. Reboot your system, and voila

Hope it helps!

Enroll with Linux training online and learn in detail about Linux.

Thanks.

answered May 24, 2019 by DareDev
• 6,890 points
0 votes

Hey, 

Even I have faced the same issue so I always tend to set the JAVA_HOME according to the /usr/bin/java . As far as I remember, I used the update-java-alternatives script instead of the update-alternatives

answered Dec 10, 2020 by Gitika
• 65,910 points
0 votes

Hello fellow techies,

Assuming you use bash shell and installed Java with the Oracle installer, you could add the following to your .bash_profile

export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/jre/bin:$PATH

This would pick the correct JAVA_HOME as defined by the Oracle installer and will set it first in your $PATH making sure it is found.

Also, you don't need to change it later when updating Java.

answered Dec 10, 2020 by Rajiv
• 8,910 points

Related Questions In Linux Administration

0 votes
1 answer

Setting environment variables in linux

You need to add more information about ...READ MORE

answered May 13, 2019 in Linux Administration by ajs3033
• 7,300 points