Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (10.2k points)

I am new to Linux system and there seem to be too many Java folders.

java -version gives me:

  • 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)

When I am trying to build a Maven project , I am getting error:

Error: JAVA_HOME is not defined correctly.

We cannot execute /usr/java/jdk1.7.0_05/bin/java

Could you please tell me which files I need to modify for root as well as not-root user and where exactly is java located?

2 Answers

0 votes
by (46k points)
  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. logout and login again, reboot, or use source /etc/profile to apply changes immediately in your current shell

0 votes
ago by (1.6k points)

To resolve the JAVA_HOME issue and build your maven projects on your Linux system. you need to check the correct Java installation path. 

The following command will list all the directories containing Java Runtime Environments under path "/usr/lib/jvm"

Command: "find /usr/lib/jvm -name jre1.* -type d"

From the list select the desired Java version and select the path that you want to use for Java installation.

To set JAVA_HOME for all users:

  • Edit the “/etc/environment” file: sudo nano /etc/environment
  • Add the following line to the end of the file, that replaces the environment with the actual path: JAVA_HOME="/usr/lib/jvm/java-11-openjdk-11.0.18+10-1.el8_6.x86_64/"
  • Now Save the file before closing it.

Finally, update the environment variables by running the

command: sudo source /etc/environment

Open a new terminal and run to verify the JAVA_HOME setting: echo $JAVA_HOME

This should display the path you set in the /etc/environment file.c

Create a Maven project build, The JAVA_HOME error should be resolved.

Related questions

0 votes
1 answer
asked Feb 17, 2021 in Java by Harsh (1.5k points)
0 votes
1 answer
asked Jul 18, 2019 in Java by Shubham (3.9k points)
0 votes
1 answer
asked Feb 23, 2021 in Java by Jake (7k points)
0 votes
1 answer
0 votes
1 answer

31k questions

32.9k answers

507 comments

693 users

Browse Categories

...