Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I had Open JDK 1.7 on CentOS; I installed Oracle's Java rpm; Oracle Java doesn't seem to exist

I started off with CentOS and OpenJDK 1.7

# java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

In order to run a specific application, I want to use Oracle's Java 1.6, provided from an RPM.

I copied the Oracle binary to a specific new directory:

# pwd
/oracleJava/jdk-6u45-linux-x64-rpm

I extracted the binary and it gave me the following files:

# ls
jdk-6u45-linux-amd64.rpm               
sun-javadb-core-10.6.2-1.1.i386.rpm  sun-javadb-javadoc-10.6.2-1.1.i386.rpm
sun-javadb-client-10.6.2-1.1.i386.rpm  sun-javadb-demo-10.6.2-1.1.i386.rpm
sun-javadb-common-10.6.2-1.1.i386.rpm  sun-javadb-docs-10.6.2-1.1.i386.rpm

I installed the RPM and the rpm utility believes that it installed properly: rpm -q jdk jdk-1.6.0_45-fcs.x86_64

# rpm -Uvh ./*.rpm
Preparing...                ########################################### [100%]
    package jdk-2000:1.6.0_45-fcs.x86_64 is already installed
# rpm -Uvh sun-javadb-*.rpm
 [I omit the feedback because it generates a formatting error]
#

However, the Java version just shows 1.7 # java -version java version "1.7.0_25" OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64) OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)

In other words, I was expecting the Oracle files to give me some new /java directory somewhere, with a new java executable that would return a different answer for "java -version"

I need that new directory so that I can set JAVA_HOME and use the 1.6 version of Java.

Helpful suggestions would be greatly appreciated. Thanks in advance.

like image 825
dataquerent Avatar asked Nov 30 '22 00:11

dataquerent


2 Answers

The Oracle JDK RPMs are horrible.

  • They do not register with the alternatives system.
  • They do not Provide (in RPM terms) "java"
  • They have messed up their RPM 'version string' and rely on Epoch (...)
  • All versions of the JDK (i.e. 1.6 vs 1.7) have the same Epoch

In order to quickly remedy your problem you can run the following:

/usr/sbin/alternatives --install /usr/bin/java java /usr/java/default/bin/java 20000

It will register and prefer the Oracle java installation as an alternative. OpenJDK has weight 16000; here we register with 20000. Once you've run this command you can switch between java versions by using the (already mentioned) alternatives --config java command.

As for a less quick fix you can use my virtual java package. It's quite possibly not perfect (I'm open for improvements ;) ), but it Provides java (making my apache-tomcat package happy) and registers with the alternatives system. This virtual package simply depends on jdk...you can find it here: https://github.com/keystep/virtual-java-rpm

like image 79
bryn Avatar answered Dec 05 '22 20:12

bryn


Run the following command to see if your JVM is getting listed.

sudo update-alternatives --config java

If your JVM gets listed select it.

like image 26
bprasanna Avatar answered Dec 05 '22 20:12

bprasanna