I have Oracle jdk7 installed on my centos6. I noticed that the /etc/profile has the lines below:

#below lines are added for Java
export JAVA_HOME="/usr/java/latest"
## export JAVA_HOME JDK ##
export JAVA_HOME="/usr/java/jdk1.7.0_75"

In order to test my assumptions on env variables and PATHs, I commented all the lines above (the export lines). I tried to load the new /etc/profile by sourcing it . /etc/profile and issued the echo $JAVA_HOME; it still returned the above path.

So, I rebooted the machine as the source didn't work. After the reboot, the echo $JAVA_HOME returns nothing, which is expected. There is nothing in ~/.bash_profile for Java.

But if I issue the command: java -version on the shell, it still returns

[root@localhost ~]# java -version
java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

Where is the Java defined in the PATH? the path in the ~/.bash_profile is as below, it doesn't have any for Java.

# User specific environment and startup programs

export PATH

set - on the shell returns the line below for the PATH variable:

  • java is probably a script, you can find out by which java, then file /usr/wahterver/java. I'll bet for either /usr/bin or /usr/local/bin which must be in you $PATH.
    – Archemar
    Commented Mar 29, 2015 at 21:24
  • @Archemar : indeed, it was there in /usr/bin/java ... when i installed the oracle jdk, it was installed in /usr/java/.. then i followed some instructions to set the desired oracle jdk instead of the open jdk. i am going to revisit the proceedure that might have set the /usr/java to /usr/bin/java.. Thanks!!!
    – OK999
    Commented Mar 29, 2015 at 21:44
  • I don't think you need to change the PATH. If you can run java -version it means that java is already in the PATH. All you have to do is set the variable JAVA_HOME.
    – Ernest A
    Commented Mar 29, 2015 at 21:51

1 Answer 1


The default PATH is set in /etc/profile. Users can modify their PATH by editing ~/.profile, ~/.bash_profile or ~/.bashrc (if they're running bash) but if they don't they will still have a PATH as defined in /etc/profile. That's why the line was


and not just


That way, the original value of PATH is kept and the new directory is simply appended. On my system, the PATH set in /etc/profile is


You probably have a very similar line in yours and that's where /usr/bin comes from.

You must log in to answer this question.

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