0

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:

env
...
JAVA_HOME=/usr/java/latest
...

So I added the following line to .bashrc:

export PATH="$PATH:$JAVA_HOME"

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?

2
  • @Christopher - That resolves the exception, but still getting -bash: java: command not found after logging out/in again Commented Jul 22, 2015 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) Commented Jul 22, 2015 at 15:24

1 Answer 1

1

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.

1
  • Neither resolve my issue. Commented Jul 22, 2015 at 15:34

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.