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.
Click on the "Terminal" icon in the desktop panel to open a terminal window and access the command prompt.
Type the command "which Java" to find the path to the Java executable file.
Type the command "su -" to become the root user.
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.
Type "export JAVA_HOME=/usr/local/Java/" at the bottom of the file. Replace "/usr/local/Java" with the location found in step two.
Save and close the "bash_profile" file.
Type the command "exit" to close the root session.
Log out of the system and log back in.
Type the command "echo $JAVA_HOME" to ensure that the path was set correctly.
- 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.