Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Java
  3. Question
Java

What's the system wide way to get java_home Ubuntu?

Asked by Alexander Coxon Oct 10, 2022 1.1K views 1 answer
Share

About this question

 I wonder whether Ubuntu itself provides a system-wide way to find the current JAVA_HOME or whether there is a right place for setting JAVA_HOME.


Mac OS X does well in this, for /usr/libexec/java_home command returns the current JAVA_HOME. But on Ubuntu, the materials I found always told me to set the $JAVA_PATH pointing to a static path, which is stored in ~/.bash_profile.


I think, however, this approach has several drawbacks:


Once Java updates, the mini version number will change, which makes the static path no longer available.

After changing the JRE used in my system with update-alternatives, I have to modify $JAVA_HOME in .bash_profile. That extra work is annoying.

Some $JAVA_HOME-required programs are not aware of .bash_profile at all. I have to set $JAVA_HOME in their start-up script, therefore a standard-and-easy way to get $JAVA_HOME seems critical to me.

Your answer

1 Answer

More Java discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Java Blogs

Guides, tips and career advice on Java from JanBask experts.