How to set the JAVA_HOME environment variable?

Solution Verified - Updated -


  • Red Hat middleware products
  • Red Hat Enterprise Linux (RHEL)
  • JDK


  • To run JBoss product, I need to set the JAVA_HOME environment variable, how to set it?
  • How do I set the JAVA_HOME environment variable?


Generally JAVA_HOME is needed to run the Java-related applications, else the results may vary. To manually set up the JAVA_HOME environment variable follow the steps:

  1. Determine the correct value for JAVA_HOME. It should point to the directory containing a bin/java executable.
  2. As the user who will use OpenJDK or any JDK vendor, open the shell configuration file. For the bash shell, this file is /home/username/.bashrc.
  3. At the bottom of the file, type the following line, replacing the hypothetical path with the actual path to use on the operating system: export JAVA_HOME="/path/to/java/home".
  4. Save the file and reload the shell configuration, i.e, source ~/.bashrc
  5. The echo $JAVA_HOME command-line must return the complete path directory to java executable.

For detailed instructions, please see JBOSS Enterprise Application Platform Installation Guide: Install OpenJDK on Red Hat Enterprise Linux

For usage of alternatives command-line tool, see solution Switching JAVA_HOME using alternatives.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.


Very vague. If this is a setting I need to change in the ROOT/SUDO profile, then please specify which profile (.bash_profile) it is.

It don't explain how to determine JAVA_HOME... i use "alternatives --display java" and works for me.