I am using a centos virtual machine instance. I have edited the /root/.bash_profile and set the JAVA_HOME path.

the changes are saved but when I type echo $JAVA_HOME, the command executes but show nothing.

typing which java shows some other folder, which doesnt exist.

please help me out

2 Answers 2


You could also set JAVA_HOME by creating a shell script in /etc/profile.d/ directory, for example:

create file: /etc/profile.d/java.sh

with following contents:

export JAVA_HOME
export PATH

Please note that directory should target place were java was installed. One above should be proper when you install Oracle JDK.

Following variables will be set during system start.


Command from .bash_profile will be applied where user log on, try to logoff and logon or restart computer.

Do you use SUN JDK or Open JDK ?

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .