0

I am trying to use java alternatives to downgrade to java 1.6 from 1.8. However despite this being set correctly in alternatives via --set the java version still returns 1.8:

  Selection    Command
-----------------------------------------------
*+ 1           /usr/java/jre1.6.0_37/bin/java
   2           /usr/java/jre1.8.0_66/bin/java

java -version
java version "1.8.0_66"

A closer look then reveals that /usr/bin/java will always point to the latest version because of:

ls -la /usr/bin/java 
lrwxrwxrwx 1 root root 26 Mar 31 11:27 /usr/bin/java -> /usr/java/default/bin/java

ls -la /usr/java/
total 20
drwxr-xr-x  4 root root 4096 Mar 31 11:30 .
drwxr-xr-x 16 root root 4096 Oct  7 11:41 ..
lrwxrwxrwx  1 root root   16 Mar 31 11:27 default -> /usr/java/latest
drwxr-xr-x  7 root root 4096 Mar 31 11:27 jre1.6.0_37
drwxr-xr-x  7 root root 4096 Mar 31 11:30 jre1.8.0_66
lrwxrwxrwx  1 root root   21 Mar 31 11:30 latest -> /usr/java/jre1.8.0_66

I have experienced this on 2 separate RHEL 5.10/11 systems. Whilst trying to replicate this on CentOS I noticed that /usr/bin/java links to /etc/alternatives/java.

Back on my RHEL system looked at /etc/alternatives/java:

ls -la /etc/alternatives/
total 24
drwxr-xr-x  2 root root  4096 Mar 31 12:02 .
drwxr-xr-x 78 root root 12288 Sep 25  2012 ..
lrwxrwxrwx  1 root root    30 Mar 31 12:02 java -> /usr/java/jre1.6.0_37/bin/java

As expected it links to the correct version which means /usr/bin/java should link to /etc/alternatives/java.

Why is this not the default behavior? Is it just a matter of changing the symlink to '/etc/alternatives/java' to manage downgrades?

kaizenCoder
  • 2,211
  • 6
  • 33
  • 64

1 Answers1

0

The RPM package creates two links: /usr/java/latest and /usr/java/default.

  1. The /usr/java/latest link will always point to the version of Java that is considered the latest version. Subsequent upgrades of the package will overwrite this value if it is not the latest version.

  2. By default, /usr/java/default points to /usr/java/latest. However, if administrators change /usr/java/default to point to another version of Java, subsequent package upgrades will be provided by the administrators and cannot be overwritten.

As for alternatives on RHEL, please follow the following:

How to use alternatives for setting default JDK?

Have you reviewed this? Problem changing Java version using alternatives

Suparna
  • 1,132
  • 1
  • 8
  • 20
  • Thanks but care to explain why `/usr/bin/java` points to the latest by default and not to 'etc/alternatives/java' ? Is it just a matter of changing the symlink to `/etc/alternatives/java` to manage downgrades? – kaizenCoder Mar 31 '16 at 01:20
  • In regard to the existing question highlighted, my issue is with downgrading. upgrade works as expected and its localized to what `/usr/bin/java` symlinks to. – kaizenCoder Mar 31 '16 at 01:41