Dev

Install Java 17 (OpenJDK 17) on Oracle Linux 9 / 8

Oracle Linux 9 and 8 both ship OpenJDK 17 in AppStream, so you can install Java 17 on Oracle Linux with one dnf command. The install is the easy part. The work starts when Java 21 lands on the same server for another app, because the runtime, the compiler and the JAVA_HOME variable each switch on their own, and an app you pinned to 17 can end up on 21 without anyone touching it.

Original content from computingforgeeks.com - post 64665

We install the JDK on both releases, look at where the files land, and then run 17 next to 21 with alternatives, a pinned JAVA_HOME and a systemd unit that ignores the system default. Every command below was run on Oracle Linux 9.8 and 8.10 in November 2026.

The short version: install java-17-openjdk-devel, then point anything that needs 17 at /usr/lib/jvm/java-17-openjdk instead of trusting whatever java is first on the PATH.

Prerequisites

When you install Java 17 Oracle Linux pulls every package from its own repositories, so you need nothing beyond a stock install. Our lab used the official Oracle Linux cloud images with the UEK kernel, and the steps are the same on a minimal ISO install because every package comes from the vendor repositories.

  • Oracle Linux 9 or Oracle Linux 8 on x86_64
  • A user with sudo rights
  • The ol9_appstream or ol8_appstream repo, enabled by default

Confirm the AppStream repo is enabled before you start. Every Java package in this guide comes from it, so if it’s missing the install fails with a “no match” error that looks like a typo in the package name.

dnf repolist

On the Oracle Linux 9 box the list looked like this. The Google Compute Engine entry is only there because the lab ran on a cloud image, and you won’t see it on your own hardware.

repo id                  repo name
google-compute-engine    Google Compute Engine
ol9_UEKR8                Oracle Linux 9 UEK Release 8 (x86_64)
ol9_appstream            Oracle Linux 9 Application Stream Packages (x86_64)
ol9_baseos_latest        Oracle Linux 9 BaseOS Latest (x86_64)

If ol9_appstream or ol8_appstream is not in your list, enable it with sudo dnf config-manager --enable followed by the repo ID. Then run dnf repolist again and check it shows up before you go further.

Pick the OpenJDK 17 package

OpenJDK 17 is split into three RPMs, and each one in this table pulls in the one above it. The one you choose decides how much lands on the server, so pick it by what the box does rather than by habit.

PackageWhat it addsInstall it when
java-17-openjdk-headlessThe JVM: java, keytool, jcmdThe server only runs a jar or WAR
java-17-openjdkAWT, Swing, fonts and sound on top of headlessThe app renders images, charts or GUI parts
java-17-openjdk-develjavac, jar, javap, jshellYou build on the box, or Maven or Gradle needs a full JDK

We install -devel below because compiling and checking class files is part of running two JDKs side by side. Know what it costs, though. The -devel package needs the full java-17-openjdk runtime, so dnf brings in the desktop libraries with it. On a runtime-only app server you should swap the package name for java-17-openjdk-headless in the install command. Headless changes more than the compiler, though. The /usr/lib/jvm/java-17-openjdk link is registered by the -devel package, so with headless alone you set JAVA_HOME to /usr/lib/jvm/jre-17-openjdk and skip the javac and compile steps. The systemd unit below already uses the jre path, so point its -cp or -jar at your own app instead of the demo class.

Install OpenJDK 17 on Oracle Linux 9

Before the install, java -version on the fresh Oracle Linux 9 image returned java: command not found, so there was no older JDK to clash with. If yours prints a version, note it now, because a JDK that is already there will show up in the alternatives menu later. Install the development package from AppStream.

sudo dnf install -y java-17-openjdk-devel

Read the transaction summary before you scroll past it. One package request turned into 126, and many of them are desktop and audio libraries (GTK, PipeWire, Flatpak portals) pulled in for the full runtime.

Transaction Summary
============================================================================================================
Install  126 Packages

Total download size: 121 M
Installed size: 416 M

That’s 416 MB on disk for a JDK. It’s fine on a build host, but on a container base or a small VM it is mostly dead weight, and every one of those packages shows up in your vulnerability scans. When dnf finishes, check the runtime, the compiler and the three RPMs in one go.

java -version
javac -version
rpm -q java-17-openjdk java-17-openjdk-headless java-17-openjdk-devel

Both tools should report the same 17 build. All three RPMs are present even though we only asked for one, because -devel depends on the full runtime and the runtime depends on headless. That chain matters later when you remove a JDK, since erasing headless takes the other two with it.

java -version, javac -version and rpm -q showing OpenJDK 17 installed on Oracle Linux 9

The runtime string says Red_Hat because Oracle rebuilds the RHEL source package, so do not read it as a sign you pulled from the wrong repo. The RPM release carries Oracle’s own suffix (2.2.0.1.el9), and that suffix is how you tell the Oracle build from the RHEL one in an inventory report.

Install OpenJDK 17 on Oracle Linux 8

The command is identical on Oracle Linux 8. What changes is the transaction, which is smaller because the older desktop stack has fewer pieces, and dnf turns on a module stream that the JDK depends on.

sudo dnf install -y java-17-openjdk-devel

The tail of the dependency list shows the javapackages-runtime stream being enabled and GTK 3 arriving as a weak dependency. Weak dependencies are optional, so a server that sets install_weak_deps=False in /etc/dnf/dnf.conf would skip GTK here and end up with a smaller install.

Installing weak dependencies:
 dconf                      x86_64  0.28.0-4.0.1.el8                 ol8_appstream      108 k
 gtk3                       x86_64  3.22.30-13.el8_10                ol8_appstream      4.5 M
Enabling module streams:
 javapackages-runtime               201801

Transaction Summary
=============================================================================================
Install  49 Packages

Total download size: 73 M
Installed size: 254 M

You don’t need to enable that module yourself. You also should not disable it afterwards, because the javapackages-filesystem package the JDK installs comes from that stream, and a later dnf run would complain about it. Run the same checks as on Oracle Linux 9.

java -version
rpm -q java-17-openjdk java-17-openjdk-headless java-17-openjdk-devel

The Java build matches the Oracle Linux 9 one exactly. Only the RPM release is different, ending in el8. So if a vendor certifies an app on a given 17 update, you can run that same update on both releases instead of keeping a separate test matrix for each.

java -version and rpm -q showing OpenJDK 17 installed on Oracle Linux 8

Since both releases get the same quarterly OpenJDK build, a fleet that mixes Oracle Linux 8 and 9 runs one Java 17 patch level. That keeps vulnerability reports simple, and it means a jar you tested on one release behaves the same on the other.

Find the OpenJDK 17 paths

Every JDK on Oracle Linux lives under /usr/lib/jvm, but most of what you see there is a symlink into /etc/alternatives. Knowing which link follows the system default and which one stays on 17 is the whole trick to running two versions, so list the directory before you add a second JDK.

ls -l /usr/lib/jvm/

Only one entry is a real directory, and its name carries the full build number. Everything else is a link, either straight to that directory or through /etc/alternatives, so what a link resolves to depends on which group it belongs to.

ls -l /usr/lib/jvm showing the java-17-openjdk and jre-17-openjdk symlinks managed by alternatives

Never hardcode that versioned directory in a config file. Its name changes with every dnf upgrade, the old path disappears, and the app fails to start on its next restart. The links fall into two groups, and only one of them is safe for a pinned app.

  • Stays on 17: /usr/lib/jvm/java-17-openjdk (full JDK)
  • Stays on 17: /usr/lib/jvm/jre-17-openjdk (runtime)
  • Follows the javac group: /usr/lib/jvm/java
  • Follows the java group: /usr/lib/jvm/jre

Use the first two for anything that must run on 17 and leave the bare java and jre links to tools that don’t care.

Add Java 21 without losing Java 17

Most servers that need 17 for one app end up with 21 for the next one. If 21 is all you need on a fresh box, the OpenJDK 21 install guide for Oracle Linux covers that on its own. Here we add it next to 17 and check what happens to the default.

sudo dnf install -y java-21-openjdk-devel

On Oracle Linux 9 this installed only three packages (headless, runtime and devel for 21), because 17 had already pulled in every shared library. The question that matters now is which java wins, and alternatives answers it.

alternatives --display java | head -20

Look at the two priority values. On Oracle Linux 9 the 17 family registers with priority 17002122 and 21 with priority 1, so automatic mode keeps 17 as the default.

java - status is auto.
 link currently points to /usr/lib/jvm/java-17-openjdk-17.0.21.1.2-2.2.0.1.el9.x86_64/bin/java
/usr/lib/jvm/java-17-openjdk-17.0.21.1.2-2.2.0.1.el9.x86_64/bin/java - family java-17-openjdk.x86_64 priority 17002122
 follower alt-java: /usr/lib/jvm/java-17-openjdk-17.0.21.1.2-2.2.0.1.el9.x86_64/bin/alt-java
 follower jcmd: /usr/lib/jvm/java-17-openjdk-17.0.21.1.2-2.2.0.1.el9.x86_64/bin/jcmd
 follower keytool: /usr/lib/jvm/java-17-openjdk-17.0.21.1.2-2.2.0.1.el9.x86_64/bin/keytool
 follower rmiregistry: /usr/lib/jvm/java-17-openjdk-17.0.21.1.2-2.2.0.1.el9.x86_64/bin/rmiregistry
 follower jre: /usr/lib/jvm/java-17-openjdk-17.0.21.1.2-2.2.0.1.el9.x86_64
 follower alt-java.1.gz: /usr/share/man/man1/alt-java-java-17-openjdk-17.0.21.1.2-2.2.0.1.el9.x86_64.1.gz
 follower java.1.gz: /usr/share/man/man1/java-java-17-openjdk-17.0.21.1.2-2.2.0.1.el9.x86_64.1.gz
 follower jcmd.1.gz: /usr/share/man/man1/jcmd-java-17-openjdk-17.0.21.1.2-2.2.0.1.el9.x86_64.1.gz
 follower keytool.1.gz: /usr/share/man/man1/keytool-java-17-openjdk-17.0.21.1.2-2.2.0.1.el9.x86_64.1.gz
 follower rmiregistry.1.gz: /usr/share/man/man1/rmiregistry-java-17-openjdk-17.0.21.1.2-2.2.0.1.el9.x86_64.1.gz
/usr/lib/jvm/java-21-openjdk-21.0.13.1.2-1.2.0.1.el9.x86_64/bin/java - family java-21-openjdk.x86_64 priority 1
 follower alt-java: /usr/lib/jvm/java-21-openjdk-21.0.13.1.2-1.2.0.1.el9.x86_64/bin/alt-java
 follower jcmd: /usr/lib/jvm/java-21-openjdk-21.0.13.1.2-1.2.0.1.el9.x86_64/bin/jcmd
 follower keytool: /usr/lib/jvm/java-21-openjdk-21.0.13.1.2-1.2.0.1.el9.x86_64/bin/keytool
 follower rmiregistry: /usr/lib/jvm/java-21-openjdk-21.0.13.1.2-1.2.0.1.el9.x86_64/bin/rmiregistry
 follower jre: /usr/lib/jvm/java-21-openjdk-21.0.13.1.2-1.2.0.1.el9.x86_64
 follower alt-java.1.gz: /usr/share/man/man1/alt-java-java-21-openjdk-21.0.13.1.2-1.2.0.1.el9.x86_64.1.gz

Oracle Linux 8 does it differently. Both families register with priority 1 there, and the output says slave where 9 says follower. In our run 17 still stayed the default on 8, but with equal priorities that is a tie rather than a guarantee, so do not rely on install order on Oracle Linux 8. The interactive menu on the 9 box confirms the result, with the *+ marker still on 17.

alternatives --config java listing OpenJDK 17 and 21 with 17 still selected after installing Java 21

So installing 21 doesn’t break a Java 17 app that calls plain java. What breaks it is someone switching the default by hand for the new app, often months later and without knowing the older app exists. The next section shows how far that switch reaches, and why the rest of this guide avoids depending on it.

Switch versions with alternatives

Run alternatives --config java and type the number of the JDK you want. We picked 2 (Java 21) on the Oracle Linux 8 box, then checked both the runtime and the compiler, because the menu only talks about java.

sudo alternatives --config java

After the switch, java reports 21 while javac still reports 17. Nothing in the menu warned about it, so you only find out if you check both binaries yourself.

Switching java to OpenJDK 21 with alternatives while javac stays on 17 on Oracle Linux 8

java and javac are separate alternatives groups. A build host can therefore compile with one JDK and run its tests with another without anyone noticing, and the mismatch only shows up when a jar reaches production. If you switch one group, switch the other in the same change. Type the number on the java-21-openjdk line again at the javac menu (2 when only 17 and 21 are installed), and leave both groups on 21 for the next three sections, because the trap with JAVA_HOME, the class version error and the systemd pin only show up when 21 is the default.

sudo alternatives --config javac

Check the result with javac -version. On our Oracle Linux 9 box it reported javac 21.0.13.1 after picking 2, so both groups now agree on 21.

Set JAVA_HOME for Java 17

Maven, Gradle, Tomcat scripts and most vendor launchers read JAVA_HOME before they look at the PATH, so this variable decides more than alternatives does. With 21 set as the system default, check where each link under /usr/lib/jvm now resolves.

readlink -f /usr/lib/jvm/java /usr/lib/jvm/java-17-openjdk /usr/lib/jvm/jre-17-openjdk

The first line of output is the trap. /usr/lib/jvm/java followed the switch to 21, while the two 17 links stayed put. A JAVA_HOME=/usr/lib/jvm/java copied from an old guide would quietly move your app to 21 the day someone runs alternatives --config javac, so write the 17 path into a profile script instead.

echo "export JAVA_HOME=/usr/lib/jvm/java-17-openjdk" | sudo tee /etc/profile.d/java17.sh

The shell you already have open started before the file existed, so it won’t have the variable yet. Test with bash -lc, which starts a fresh login shell and reads /etc/profile.d.

bash -lc "echo JAVA_HOME=\$JAVA_HOME; \$JAVA_HOME/bin/java -version"

The new login shell gets JAVA_HOME on 17 even though plain java is 21 on this box. Tools that honour the variable will build and run on 17, while a script that calls bare java still gets 21, so check which one your launcher uses.

JAVA_HOME set to /usr/lib/jvm/java-17-openjdk in /etc/profile.d on Oracle Linux 9

A profile script is fine for interactive users and build agents that log in. Services started by systemd never read /etc/profile.d, though, so they need the path in the unit itself, which we set up two sections down. Our Apache Maven guide for Rocky Linux and Fedora uses the same JAVA_HOME approach for build hosts on the EL family.

Compile for Java 17 with a newer javac

The failure you are most likely to hit when 17 and 21 share a box is a jar built by the 21 compiler and deployed to a 17 runtime. We reproduced it with a tiny class that prints the running Java version and home directory, so you can see the problem and the fix on your own server. Create the file first.

mkdir -p ~/demo && vim ~/demo/Version.java

Paste this class and save the file. It prints java.home as well as the version, so you can see which JDK directory ran it, not just the release number.

public class Version {
    public static void main(String[] args) {
        System.out.println("java.version=" + System.getProperty("java.version"));
        System.out.println("java.home=" + System.getProperty("java.home"));
    }
}

With javac switched to 21, compile the class, check its class file version with javap, and run it with the Java 17 binary.

cd ~/demo && javac Version.java && javap -v Version.class | grep major
/usr/lib/jvm/java-17-openjdk/bin/java Version

The class comes out as major version 65, and Java 17 refuses to load it. The exit code was 1, so a service built this way fails at startup rather than at some later request, which at least makes the problem easy to spot.

UnsupportedClassVersionError: class file version 65.0

This is the exact error from the Oracle Linux 9 run. You’ll see the same text in a Tomcat or Spring Boot log when a newer build lands on an older runtime.

Error: LinkageError occurred while loading main class Version
	java.lang.UnsupportedClassVersionError: Version has been compiled by a more recent version of the Java Runtime (class file version 65.0), this version of the Java Runtime only recognizes class file versions up to 61.0

Class file version 61 is Java 17 and 65 is Java 21, so the message names both the compiler that built the jar and the runtime trying to load it. You don’t have to switch javac back to fix it. Tell the 21 compiler to target 17 with --release, which also stops the build if the code calls an API that 17 doesn’t have.

cd ~/demo && rm -f Version.class && javac --release 17 Version.java && javap -v Version.class | grep major
/usr/lib/jvm/java-17-openjdk/bin/java Version

Now the class is major version 61 and runs on 17. The compiler did not change, only its target, so a build agent can keep 21 as its default and still ship jars that every Java 17 server accepts.

UnsupportedClassVersionError class file version 65.0 on Java 17 and the javac --release 17 fix

In Maven the same fix is <maven.compiler.release>17</maven.compiler.release> in the POM, and in Gradle it is a Java toolchain set to 17. Either way the build target stops depending on which javac happens to be the default on the build agent. That is the setting we’d add before installing 21 anywhere near a Java 17 project, because it turns a production startup failure into a compile error on the build host, where it costs a few minutes instead of an outage.

Pin a systemd service to Java 17

A service should never depend on what alternatives says, because that setting belongs to whoever logged in last. Give the unit the absolute path to the 17 runtime instead. Start by copying the test class somewhere a service can read it.

sudo mkdir -p /opt/version && sudo cp ~/demo/Version.class /opt/version/

Then create the unit file. A real app would point -cp or -jar at its own files, but the pinning lines stay exactly the same.

sudo vim /etc/systemd/system/version17.service

Add the following. Environment=JAVA_HOME covers launcher scripts that read the variable, and ExecStart calls the 17 binary directly so nothing on the PATH is involved.

[Unit]
Description=Java 17 pinned demo

[Service]
Type=oneshot
Environment=JAVA_HOME=/usr/lib/jvm/jre-17-openjdk
ExecStart=/usr/lib/jvm/jre-17-openjdk/bin/java -cp /opt/version Version

[Install]
WantedBy=multi-user.target

Reload systemd, start the unit and read what it printed. We left the system default on 21 for this test, so the result only comes back as 17 if the pin works.

sudo systemctl daemon-reload
sudo systemctl start version17.service
sudo journalctl -u version17.service --no-pager -o cat | tail -4
java -version 2>&1 | head -1

The service ran on 17 while the shell’s java was 21. The java.home line in the journal is the proof, because it is printed by the JVM that actually ran rather than read from a config file.

systemd service running on Java 17 while the system default java is OpenJDK 21

That is the pattern for any real Java 17 service. On Oracle Linux 9 the journal ended with Deactivated successfully instead of Succeeded, which is only a newer systemd wording for the same result. If you run Tomcat from our Tomcat setup on Rocky Linux, set its JAVA_HOME to the jre-17-openjdk path rather than the default /usr/lib/jvm/jre, which moves with the java group.

Once you have seen the pin hold, put the default back on 17. In scripts and Ansible tasks, skip the menu and set both groups by family name. That is what we’d put in configuration management, since the numbers in the menu depend on install order and can differ between two servers that look identical.

sudo alternatives --set java java-17-openjdk.x86_64
sudo alternatives --set javac java-17-openjdk.x86_64
alternatives --display java | head -2
javac -version

On the Oracle Linux 9 box the status flipped to manual, so a later JDK install with a higher priority won’t take over the default. That is the state you want on a server that exists to run a Java 17 app. It also documents intent, since anyone who runs alternatives --display java later sees that a person chose 17 on purpose.

java - status is manual.
 link currently points to /usr/lib/jvm/java-17-openjdk-17.0.21.1.2-2.2.0.1.el9.x86_64/bin/java
javac 17.0.21.1

To hand control back to priorities, run sudo alternatives --auto java and the same for javac. On both of our boxes that returned the default to 17, but on Oracle Linux 8 it is still the tie described above, so we’d keep the manual setting on any server where 17 must win.

Keep Java 17 patched

OpenJDK 17 on Oracle Linux gets the same quarterly updates as RHEL. AppStream also keeps the older builds around, so you can step back one release if an update breaks something, and listing them is the quickest way to see where you stand.

dnf list --showduplicates java-17-openjdk-headless | tail -4

The Oracle Linux 9 repo had these four most recent builds. Each update adds a new line, and both 17.0.20 and 17.0.21 got a second .1 build after the first one shipped, so check the full version string rather than just the update number.

java-17-openjdk-headless.x86_64     1:17.0.20.0.8-1.2.0.1.el9     ol9_appstream
java-17-openjdk-headless.x86_64     1:17.0.20.1.1-1.2.0.1.el9     ol9_appstream
java-17-openjdk-headless.x86_64     1:17.0.21.0.9-2.2.0.1.el9     ol9_appstream
java-17-openjdk-headless.x86_64     1:17.0.21.1.2-2.2.0.1.el9     ol9_appstream 

Our patch routine for a Java 17 server has three steps.

  1. Run sudo dnf upgrade 'java-17-openjdk*'
  2. Restart every service that runs on Java 17
  3. Check the new build in each service’s log or java -version

Because every path in this guide uses the java-17-openjdk and jre-17-openjdk links, a normal dnf upgrade moves your services to the new build with no config edits. Nobody has to edit a unit file or a profile script after an update, which is the main reason we avoid the versioned directory names. The restart is what applies the patch, though, since a running JVM keeps the old libraries mapped until it stops. Our Java4Shell patch walkthrough for RHEL-family servers shows how to find JVMs still running a replaced build.

Plan the exit too. Red Hat’s OpenJDK life cycle page lists full support for OpenJDK 17 until December 31, 2027, with extended life cycle support (ELS-1) running to January 31, 2029, and the Oracle Linux packages track those builds. Pin your Java 17 apps by path today and compile them with --release 17, and the move to 21 becomes a one-line change per service instead of a hunt for every java on the PATH.

Keep reading

How to Upgrade Fedora 44 to Fedora 45 (GUI, CLI and Rollback) Fedora How to Upgrade Fedora 44 to Fedora 45 (GUI, CLI and Rollback) Java4Shell (CVE-2026-114938): Find and Patch Vulnerable JVMs Security Java4Shell (CVE-2026-114938): Find and Patch Vulnerable JVMs Upgrade Ubuntu 24.04 to Ubuntu 26.04 LTS (Step by Step) Ubuntu Upgrade Ubuntu 24.04 to Ubuntu 26.04 LTS (Step by Step) Install Waydroid on Fedora 45 to Run Android Apps Fedora Install Waydroid on Fedora 45 to Run Android Apps Encapsule on Fedora 45: Isolated Dev Containers vs Toolbx Containers Encapsule on Fedora 45: Isolated Dev Containers vs Toolbx Setup Mail Server on Rocky Linux 10 with Postfix, Dovecot, MariaDB and Roundcube Networking Setup Mail Server on Rocky Linux 10 with Postfix, Dovecot, MariaDB and Roundcube

Leave a Comment

Press ESC to close