Linux Logo

Set the Envionrment Variable in CentOS through Best Practice

In the past, to make an environment variable perminant, I would append to the /etc/profile file the environment variable for JAVA_HOME for example and update the PATH. While this does work, it has recently come to my attention that a more appropriate and easier method exists which does not involve editing the /etc/profile file.

For this example, the environment variable, JAVA_HOME will be created for Java. Navigate to the /etc/profile.d directory. Use vim or your favorite editor to create a file called With the full path, the file is /etc/profile.d/

This Java was installed using yum. Your path may likely vary. Add the following content to the file and save it. Done.

export JRE_HOME=/usr/lib/jvm/java-1.6.0-openjdk-
export PATH=$PATH:$JRE_HOME/bin

export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-

export PATH=$PATH:$JAVA_HOME/bin

To avoid restarting the server, issue the following command to start the script.


Check your path

# echo $JAVA_HOME