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

16,599

Solution 1

The problem is that Oracle's RPMs are (wilfully IMO!) ignorant of the "alternatives" system.

Instead, they install stuff in a non-standard place (/usr/java) and then expect the user / system administrator to mess with the PATH variable ... by hand.

It is a nuisance!


So what has probably happened in your case is that your JDK / JRE has been installed in a subdirectory of /usr/java ... but since you haven't added the relevant bin subdirectory to the front of your PATH you are still picking up the OpenJDK tools via the java command name.


You can fix this after the fact by using "alternatives" to configure and then select the Oracle commands. But it is messy, especially if you want the JDK tools as well. (There are a lot of them!)

If you use Chef, another approach is to use the "java" cookbook to do the installation.

Solution 2

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

Solution 3

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

sudo update-alternatives --config java

If your JVM gets listed select it.

Solution 4

Please check that whether your JAVA_HOME points to JDK 6 using echo $JAVA_HOME. In order change your JAVA_VERSION to Java 6, you need to point to the Java development KIT 6. You also need to add the bin directory to the $PATH variable. Please ensure that JDK6 bin directory comes in the $PATH prior to other JDK bin,if any. You can check the version of your Java in the environment by command java -version.The other answer by learningloop is very perfect to switch between different Java configurations

Share:
16,599
dataquerent
Author by

dataquerent

(quoted from Turjan of Miir (The Dying Earth)) In this fashion did Turjan enter his apprenticeship to Pandelume. Day and far into the opalescent Embelyon night he worked under Pandelume's unseen tutelage. He learned the secret of renewed youth, many spells of the ancients, and a strange abstract lore that Pandelume termed "Mathematics." "Within this instrument," said Pandelume, "resides the Universe. Passive in itself and not of sorcery, it elucidates every problem, each phase of existence, all the secrets of time and space. Your spells and runes are built upon its power and codified according to a great underlying mosaic of magic. The design of this mosaic we cannot surmise; our knowledge is didactic, empirical, arbitrary. Phandaal glimpsed the pattern and so was able to formulate many of the spells which bear his name. I have endeavored through the ages to break the clouded glass, but so far my research has failed. He who discovers the pattern will know all of sorcery and be a man powerful beyond comprehension." So Turjan applied himself to the study and learned many of the simpler routines. "I find herein a wonderful beauty," he told Pandelume. "This is no science, this is art, where equations fall away to elements like resolving chords, and where always prevails a symmetry either explicit or multiplex, but always of a crystalline serenity."

Updated on June 07, 2022

Comments

  • dataquerent
    dataquerent almost 2 years

    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.

  • dataquerent
    dataquerent over 10 years
    This is the best answer, although the answers that explain the RedHat "alternatives" are very useful.
  • dataquerent
    dataquerent over 10 years
    That is a great command and I will definitely be using it for other purposes in the near future. Thank you for that. For my immediate purpose, the best thing is to set JAVA_HOME to /usr/java/jdk1.6.0_45/bin just to get the current application to do what the vendor expects.
  • dataquerent
    dataquerent over 10 years
    Thank you. I will be looking at your github for a different machine; the current machine belongs to someone else and the owner wants it to comply with the vendor's Oracle guidelines.
  • dataquerent
    dataquerent over 10 years
    Thank you. The $PATH variable will be my first task today.
  • bryn
    bryn over 10 years
    You're welcome! The alternatives command should give you what you need. Just to be clear: The virtual-java package is just a metadata ("virtual") package - it does not modify any behavior of the Oracle RPM, just adds some missing bits for better system integration ;) By the way, in regard to the accepted answer: I don't have time to verify, but I was pretty sure the Oracle RPM sets up the /usr/bin/java symlink, but as it does not register with alternatives it depends on the order of installation. If you install the Oracle JDk and then install/update OpenJDK, the symlink will be replaced.
  • Chaminda Bandara
    Chaminda Bandara about 3 years
    Thank you so much for the information and guide. This is horrible. If I need to install from jdk6 to jdk11. What would be the best method ?
  • bryn
    bryn almost 3 years
    @ChamindaBandara I guess you found a method by now, but my first question would be: Do you still need JDK6? Just removing it might be the best way forward! :D
  • Chaminda Bandara
    Chaminda Bandara almost 3 years
    Thank you for the reply and I found a solution. The reason to install it was that our development team requesting, that's why...