I'm aware of the which command but when I run it on Java, I get the following path:

$ which java

What I'm looking for, I think, is the Java path I get when I run the following Maven command:

$ mvn -version
Apache Maven 3.6.3
Java version:, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.13.0-1021-aws", arch: "amd64", family: "unix"

Isn't the latter (/usr/lib/jvm/java-11-openjdk-amd64) the correct Java home path? If so, which command would directly return it?

Running the java version command doesn't return any paths.

  • /bin/java is probably a symlink.
    – jordanm
    Apr 13, 2022 at 14:25

1 Answer 1


readlink -f /bin/java will trace the symlink all the way down to the actual executable. The result you get will be something of the form /usr/lib/jvm/java-11-openjdk-amd64/bin/java. Omit the /bin/java part at the end to get the JDK/JRE home path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.