Note: this post was updated to reflect updated Oracle Java versions
We recently announced that Oracle Java, Oracle’s widely adopted and proven Java Development Kit, is now included with Oracle Cloud Infrastructure subscriptions at no extra cost.
In this blog post I show how to install Oracle Java on Oracle Linux running in an OCI compute shape by using RPMs available from the OCI yum service.
Oracle Java RPMs are available for Oracle Linux 7 and Oracle Linux 8 in the ol7_oci_included and ol8_oci_included repositories respectively. Current Oracle Linux images are provisioned with these repositories installed and enabled.
As of this writing, the repositories contain Oracle Java 8, 11, 12, 13, and 14 for Oracle Linux 7:
$ yum list jdk* Loaded plugins: langpacks, ulninfo Available Packages jdk-11.0.3.x86_64 2000:11.0.3-ga ol7_oci_included jdk-11.0.4.x86_64 2000:11.0.4-ga ol7_oci_included jdk-11.0.5.x86_64 2000:11.0.5-ga ol7_oci_included jdk-11.0.7.x86_64 2000:11.0.7-ga ol7_oci_included jdk-12.0.1.x86_64 2000:12.0.1-ga ol7_oci_included jdk-12.0.2.x86_64 2000:12.0.2-ga ol7_oci_included jdk-13.x86_64 2000:13-ga ol7_oci_included jdk-13.0.1.x86_64 2000:13.0.1-ga ol7_oci_included jdk-14.x86_64 2000:14-ga ol7_oci_included jdk-14.0.1.x86_64 2000:14.0.1-ga ol7_oci_included jdk1.8.x86_64 2000:1.8.0_251-fcs ol7_oci_included
...and Oracle Java 8, 11, and 14 for Oracle Linux 8:
yum list jdk* Last metadata expiration check: 6:09:09 ago on Mon 27 Apr 2020 11:57:02 AM GMT. Installed Packages jdk-11.0.7.x86_64 2000:11.0.7-ga ol8_oci_included jdk-14.0.1.x86_64 2000:14.0.1-ga ol8_oci_included jdk1.8.x86_64 2000:1.8.0_251-fcs ol8_oci_included
To install Oracle Java 14, version 14.0.1:
$ sudo yum install jdk-14.0.1
To confirm the Java version:
$ java -version java version "14.0.1" 2020-04-14 Java(TM) SE Runtime Environment (build 14.0.1+7) Java HotSpot(TM) 64-Bit Server VM (build 14.0.1+7, mixed mode, sharing)
If you install multiple version of the JDK, you may want to set the default version using alternatives. For example, let’s first install Oracle Java 8:
$ sudo yum install -y jdk1.8
The alternatives command shows that two programs provide java:
$ sudo alternatives --config java There are 2 programs which provide 'java'. Selection Command ----------------------------------------------- *+ 1 /usr/java/jdk-14.0.1/bin/java 2 /usr/java/jdk1.8.0_251-amd64/jre/bin/java
Choosing selection 2 sets the default to JDK 1.8 (Oracle Java 8):
$ java -version java version "1.8.0_251" Java(TM) SE Runtime Environment (build 1.8.0_251-b08) Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
Oracle Cloud Infrastructure includes Oracle Java —with support and updates— at no additional cost. By providing Oracle Java RPMs in OCI’s yum service, installation is greatly simplified. Try it for free with Oracle Cloud Free Tier.