DISCOVER
×
Loading ...

How to set java home on centos

Updated July 20, 2017

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.

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

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

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

  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. 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. Save and close the "bash_profile" file.

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

  8. Log out of the system and log back in.

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

  10. Tip

    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.

Loading ...

Resources

About the Author

Kristen Waters has been writing for the computer industry since 2004. She has written training materials for both large and small computer companies as well as how-to and informative articles for many online publications. She holds Bachelor of Science degrees from both York College of Pennsylvania and the University of Maryland.

Loading ...