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,985 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,770 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,870 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
1,304 views
–1 vote
1 answer

How to get octal file permission in linux?

You can use this: stat -c "%a %n" ...READ MORE

answered Jan 3, 2019 in Linux Administration by Omkar
• 69,220 points
2,625 views
0 votes
1 answer

How to create a symlink in Linux?

To create a symbolic link, you can ...READ MORE

answered Feb 1, 2019 in Linux Administration by Omkar
• 69,220 points
1,224 views
0 votes
1 answer

generating a list of files with their absolute path in Linux

If you find an absolute path to start with, ...READ MORE

answered May 16, 2019 in Linux Administration by Upasana
• 8,620 points
1,405 views
0 votes
1 answer
0 votes
2 answers

Java Environment Variables

--- To set java path --- There are ...READ MORE

answered Dec 3, 2018 in Java by Sushmita
• 6,920 points
1,473 views
0 votes
1 answer

Serverspec doesn't check package version correctly

Specinfra is escaping the characters in the with_version chain ...READ MORE

answered Aug 2, 2018 in DevOps Tools by Kalgi
• 52,350 points
1,367 views
0 votes
1 answer

How do I set variable if a specific package version is installed in CFEngine?

Here is what you can do.Just use packagesmatching to ...READ MORE

answered Jul 12, 2018 in Other DevOps Questions by Atul
• 10,240 points
1,210 views
0 votes
1 answer

Finding pat of afile in linux

You can use readlink command: readlink -f filename.txt READ MORE

answered Mar 15, 2019 in Linux Administration by DareDev
• 6,890 points
967 views
0 votes
1 answer

How to find the group associated with a user in linux?

To list all the groups groups or to list ...READ MORE

answered Jun 21, 2019 in Linux Administration by DareDev
• 6,890 points
966 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP