All the Java components installed on Fedora (20) are provided by OpenJDK (Open Java Development Kit), a Free Software implementation of Java SE (Standard Edition).
It’s all you’ll need except when you have to install an application that requires Oracle JRE (Java Runtime Environment). One such application is the community edition of Datastax Cassandra, a NoSQL database. I thought I could uninstall OpenJDK and install Oracle JRE, but tightly-coupled dependencies made it a non-trivial task.
Later I found that both versions of Java (JRE) can live happily on the same machine by the use of the alternatives system, which is what this post is all about: How to install and use Oracle JRE on a Fedora machine that has OpenJDK JRE already installed. I wasn’t sure how this was going to play out, but so far, it has worked for me.
Here’s how I did it.
1. Download Oracle JRE: You can do that by visiting Java SE Downloads. For my installation, I downloaded the Java SE 7u67 version, to match the installed OpenJDK version. Save the RPM file to your Downloads folder.
2. Install Oracle JRE: To install it, cd to the Downloads folder, su to root, then type:
yum install jre-7u67-linux-x64.rpm. It will be installed in the /usr/java directory. An ls of that directory will show the version you just installed. It should be jre1.7.0_67. OpenJDK is installed in /usr/bin/java. If you type
java -version, the output should tell you what version the system is using. It should read something like this:
java version "1.7.0_65"
OpenJDK Runtime Environment (fedora-220.127.116.11.fc20-x86_64 u65-b17)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
3. Configure the system to use Oracle JRE: This is where the alternatives command comes in. And it has to be run as root. To set up the newly installed Oracle JRE for use by the system, type:
alternatives --install /usr/bin/java/ java /usr/java/jre1.7.0_67/bin/java 20000. After that command, the system will still be reporting OpenJDK when you query for the installed version. To change that, type:
alternatives --config java. The system will present the two versions installed. Select the option 2, which should be Oracle JRE. Afterwards, query for the installed version to verify that the system is now using Oracle JRE. If you ever need to switch back to OpenJDK, just run the
alternatives --config java.