How to set java home on centos

Written by kristen waters
  • Share
  • Tweet
  • Share
  • Email

The JAVA_HOME environment variable provides the path to the Java executable file for other system processes. When you install Java on the CentOS operating system, this variable is not automatically set. The "bash_profile" file contains all of the environment variables set by the user. There is a "bash_profile" file for the entire system as well as a separate "bash_profile" file for each user. Placing environment variables in this file ensures that they are set each time you log into the system.

Skill level:


  1. 1

    Click on the "Terminal" icon in the desktop panel to open a terminal window and access the command prompt.

  2. 2

    Type the command "which Java" to find the path to the Java executable file.

  3. 3

    Type the command "su -" to become the root user.

  4. 4

    Type the command "vi /root/.bash_profile" to open the system "bash_profile" file in the Vi text editor. You can replace "vi" with your preferred text editor.

  5. 5

    Type "export JAVA_HOME=/usr/local/Java/" at the bottom of the file. Replace "/usr/local/Java" with the location found in step two.

  6. 6

    Save and close the "bash_profile" file.

  7. 7

    Type the command "exit" to close the root session.

  8. 8

    Log out of the system and log back in.

  9. 9

    Type the command "echo $JAVA_HOME" to ensure that the path was set correctly.

Tips and warnings

  • If you want to set JAVA_HOME for your own account, not system-wide, place the line "export JAVA_HOME=/usr/local/Java/" in the "/home/.bash_profile" file. You do not have to be the root user.

Don't Miss


  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.