I have installed a new JRE on my RedHat linux system.

lsb_release -i -r
Distributor ID: CentOS
Release:    6.5

I have updated the symbolic links pointing to the desired Java installation:

ls -l /usr/bin/java
lrwxrwxrwx. 1 root root 21 Jul 21 16:27 /usr/bin/java -> /usr/java/jre1.8.0_51

ls -l /usr/java/latest
lrwxrwxrwx. 1 root root 21 Jul 21 15:34 /usr/java/latest -> /usr/java/jre1.8.0_51

ls -l /etc/alternatives/java
lrwxrwxrwx. 1 root root 20 Jul 21 17:42 /etc/alternatives/java -> /usr/java/glassfish4

But, now when I run:

java -version
-bash: java: command not found

Environment variables:


So I added the following line to .bashrc:


But still get:

java -version
-bash: java: command not found

Resolved - correct line in bashrc:

export PATH=$PATH:/usr/java/jre1.8.0_51/bin/

I don't know why, but using the environment variable pointing to symbolic link export PATH="$PATH:$JAVA_HOME" does not work, even though it's correctly resolving:

ls -l /usr/java/latest
    lrwxrwxrwx. 1 root root 21 Jul 21 15:34 /usr/java/latest -> /usr/java/jre1.8.0_51

I would really like to understand why?

  • @Christopher - That resolves the exception, but still getting -bash: java: command not found after logging out/in again Jul 22 '15 at 15:13
  • @Christopher - There is a symbolic link in the jre1.8.0_51 directory that points to the bin directory java -> /usr/bin/java that was part of the installation (I did not create it). I don't know the answer to your question: Is this applicable on your RHEL system? (/usr/sbin/alternatives --config java) Jul 22 '15 at 15:24

The reason it didn't work with $JAVA_HOME is that $JAVA_HOME isn't the same thing as $JAVA_HOME/bin. Your binaries (java, javac, javaws, etc) are all found in the bin directory inside your $JAVA_HOME, not in the $JAVA_HOME itself.

The working line in your question points towards /usr/java/jre1.8.0_51/bin; the JAVA_HOME variable points towards /usr/java/latest, which is a symlink to /usr/java/jre1.8.0_51. That's clearly not the same place.

If you use

export PATH="$PATH:$JAVA_HOME/bin"

it will work.

  • Neither resolve my issue. Jul 22 '15 at 15:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.