1

I have the following setup (on multiple machines with RHEL7):


$ which java 
/usr/bin/java

$ ls -ltr /usr/bin/java 
/usr/bin/java -> /etc/alternatives/java

$ ls -ltr /etc/alternatives/java
/etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.242b08-1.e17.x86_64/jre/bin/java

$ echo $JAVA_HOME
/etc/alternatives/jre_1.8.0_openjdk

$ ls -ltr /etc/alternatives/jre_1.8.0_openjdk
/etc/alternatives/jre_1.8.0_openjdk -> /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.242-1.e17.x86_64

I need to update to version 251 so I took the corresponding .tar.gz from artifactory , extract it in /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.251 and now I need to update all the simlink in order to use the latest java version.

Using the man pages of alternatives I did:

alternatives --install /usr/bin/java java /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.251/bin/java

Which modified /etc/alternatives/java but due to the fact that $JAVA_HOME=/etc/alternatives/jre_1.8.0_openjdk I need to modify/update /etc/alternatives/jre_1.8.0_openjdk .

I am not sure what to put as the <link> in alternatives --install <link> <name> <path> <priority> in order to update /etc/alternatives/jre_1.8.0_openjdk.

I'm not even sure that this is the correct approach towards updating java version . Thx

2
  • You don't need to create any symlinks. All you need to do is prepend /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.251/bin to your PATH and /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.251/lib to your LD_LIBRARY_PATH and then set the JAVA_HOME` as /usr/lib/jvm/jre-1.8.0-openjdk-1.8.0.251. Jul 14, 2020 at 2:21
  • You could also upgrade your RHEL systems, the current version of OpenJDK 8 in RHEL 7 is 262. Jul 14, 2020 at 7:08

1 Answer 1

2

This is the correct approach to hand-inserting an alternative in the alternatives system.

Your alternatives tool is a port of the original Debian update-alternatives tool. With that tool, and your port, there is

update-alternatives --display jre_1.8.0_openjdk

which should tell you the "generic name" to use with --install. The vanilla Debian tool also has

update-alternatives --query jre_1.8.0_openjdk
for a machine-readable form that can be used in pipelines, which your system does not have, however.

However: On RHEL, Java installations are installed with the --slave option to --install so that the JRE is switched in lockstep with the java program. In fact, there are between 20 and 50 --slave options that the install scripts for the packages set up. Witness the likes of this post-install script template for OpenJDK from AdoptOpenJDK (which isn't even setting up a JRE alternative, notice) for example.

Really this isn't something that you are going to be able to construct, error-free, longhand, to match what you already have. Don't download and install from raw TAR archives. Use the packages.

You must log in to answer this question.

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