{"id":16236,"date":"2026-03-18T04:18:57","date_gmt":"2026-03-18T01:18:57","guid":{"rendered":"https:\/\/computingforgeeks.com\/?p=16236"},"modified":"2026-03-24T11:58:50","modified_gmt":"2026-03-24T08:58:50","slug":"install-java-rhel-rocky-almalinux","status":"publish","type":"post","link":"https:\/\/computingforgeeks.com\/install-java-rhel-rocky-almalinux\/","title":{"rendered":"Install Java 21 LTS (OpenJDK) on RHEL 10 \/ Rocky Linux 10 \/ AlmaLinux 10"},"content":{"rendered":"\n<p>Java 21 is the latest long-term support (LTS) release from Oracle and the OpenJDK community, with support guaranteed until at least September 2029. If you are running production workloads on RHEL 10, Rocky Linux 10, or AlmaLinux 10, this is the version you should be deploying. It brings virtual threads, pattern matching improvements, and a range of performance gains over Java 17 and earlier releases.<\/p>\n\n\n\n<p>In this guide, I will walk you through two methods to install OpenJDK 21 on RHEL 10-based distributions: using the default AppStream repository and using the Eclipse Temurin (Adoptium) repository. We will also cover setting JAVA_HOME properly, managing multiple Java versions with the alternatives system, and configuring Java for build tools and application servers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>Before you begin, make sure you have the following in place:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A running installation of RHEL 10, Rocky Linux 10, or AlmaLinux 10<\/li>\n\n\n\n<li>Root or sudo access to the server<\/li>\n\n\n\n<li>An active internet connection for package downloads<\/li>\n\n\n\n<li>The system should be up to date &#8211; run <code>sudo dnf update -y<\/code> before proceeding<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">JDK vs JRE &#8211; Which One Do You Need?<\/h2>\n\n\n\n<p>Before installing, understand the difference between the two main packages:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>JRE (Java Runtime Environment)<\/strong> &#8211; contains only the runtime needed to execute Java applications. Install this on servers that only run pre-compiled Java apps like Tomcat, Elasticsearch, or Kafka.<\/li>\n\n\n\n<li><strong>JDK (Java Development Kit)<\/strong> &#8211; includes the JRE plus development tools like <code>javac<\/code> (compiler), <code>jdb<\/code> (debugger), and <code>jar<\/code> (archive tool). Install this if you need to compile Java code, run Maven or Gradle builds, or do any development work.<\/li>\n<\/ul>\n\n\n\n<p>My recommendation: install the full JDK unless you are absolutely certain you only need the runtime. The extra disk space is minimal and it saves you from headaches later when a tool expects <code>javac<\/code> to be present.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Method 1 &#8211; Install OpenJDK 21 from AppStream Repository<\/h2>\n\n\n\n<p>RHEL 10 and its derivatives ship OpenJDK 21 in the AppStream repository. This is the simplest and most straightforward installation method, and the packages receive security updates through your normal system update process.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1 &#8211; Install OpenJDK 21 JDK<\/h3>\n\n\n\n<p>To install the full JDK (recommended):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install -y java-21-openjdk-devel<\/code><\/pre>\n\n\n\n<p>If you only need the JRE:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install -y java-21-openjdk<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2 &#8211; Verify the Installation<\/h3>\n\n\n\n<p>Check the Java runtime version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>java -version<\/code><\/pre>\n\n\n\n<p>Expected output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openjdk version \"21.0.6\" 2025-01-21 LTS\nOpenJDK Runtime Environment (Red_Hat-21.0.6.0.7-1) (build 21.0.6+7-LTS)\nOpenJDK 64-Bit Server VM (Red_Hat-21.0.6.0.7-1) (build 21.0.6+7-LTS, mixed mode, sharing)<\/code><\/pre>\n\n\n\n<p>If you installed the JDK, also verify the compiler:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>javac -version<\/code><\/pre>\n\n\n\n<p>Expected output:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>javac 21.0.6<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Method 2 &#8211; Install Eclipse Temurin (Adoptium) from Official Repository<\/h2>\n\n\n\n<p>Eclipse Temurin is a production-ready OpenJDK distribution maintained by the Adoptium project. It is a solid alternative if you want builds that are independent of your OS vendor&#8217;s release cycle, or if your organization standardizes on Temurin across different platforms.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1 &#8211; Add the Adoptium Repository<\/h3>\n\n\n\n<p>First, create the repository configuration file:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat &lt;&lt; 'EOF' | sudo tee \/etc\/yum.repos.d\/adoptium.repo\n[Adoptium]\nname=Adoptium\nbaseurl=https:\/\/packages.adoptium.net\/artifactory\/rpm\/rhel\/$releasever\/$basearch\nenabled=1\ngpgcheck=1\ngpgkey=https:\/\/packages.adoptium.net\/artifactory\/api\/gpg\/key\/public\nEOF<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2 &#8211; Install Temurin 21 JDK<\/h3>\n\n\n\n<p>Install the package:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install -y temurin-21-jdk<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3 &#8211; Verify the Installation<\/h3>\n\n\n\n<p>Check the installed version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>java -version<\/code><\/pre>\n\n\n\n<p>You should see output similar to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>openjdk version \"21.0.6\" 2025-01-21 LTS\nOpenJDK Runtime Environment Temurin-21.0.6+7 (build 21.0.6+7-LTS)\nOpenJDK 64-Bit Server VM Temurin-21.0.6+7 (build 21.0.6+7-LTS, mixed mode, sharing)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Set JAVA_HOME System-Wide<\/h2>\n\n\n\n<p>Many Java applications, build tools, and frameworks expect the <code>JAVA_HOME<\/code> environment variable to be set. The cleanest way to do this system-wide on RHEL-based systems is to create a script in <code>\/etc\/profile.d\/<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1 &#8211; Find Your Java Installation Path<\/h3>\n\n\n\n<p>Run the following to find where Java is installed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>dirname $(dirname $(readlink -f $(which java)))<\/code><\/pre>\n\n\n\n<p>For the AppStream OpenJDK package, this will typically return something like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/usr\/lib\/jvm\/java-21-openjdk-21.0.6.0.7-1.el10.x86_64<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2 &#8211; Create the JAVA_HOME Profile Script<\/h3>\n\n\n\n<p>Create <code>\/etc\/profile.d\/java.sh<\/code> with the following content:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat &lt;&lt; 'EOF' | sudo tee \/etc\/profile.d\/java.sh\nexport JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))\nexport PATH=$JAVA_HOME\/bin:$PATH\nEOF<\/code><\/pre>\n\n\n\n<p>Make it executable:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo chmod +x \/etc\/profile.d\/java.sh<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3 &#8211; Load and Verify<\/h3>\n\n\n\n<p>Source the script to apply it to your current session:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>source \/etc\/profile.d\/java.sh<\/code><\/pre>\n\n\n\n<p>Verify JAVA_HOME is set correctly:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo $JAVA_HOME<\/code><\/pre>\n\n\n\n<p>This script will be loaded automatically for all users on their next login.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Manage Multiple Java Versions with Alternatives<\/h2>\n\n\n\n<p>If you have more than one Java version installed on the same system, for example Java 17 for a legacy app and Java 21 for newer workloads, RHEL&#8217;s alternatives system lets you switch between them cleanly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">List Available Java Versions<\/h3>\n\n\n\n<p>See all installed Java runtimes registered with alternatives:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo alternatives --config java<\/code><\/pre>\n\n\n\n<p>This shows a numbered list of available versions. Enter the number corresponding to the version you want to use as the default, then press Enter.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Switch the Java Compiler<\/h3>\n\n\n\n<p>You should also switch the compiler to match:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo alternatives --config javac<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Verify After Switching<\/h3>\n\n\n\n<p>Always verify after making a change:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>java -version\njavac -version<\/code><\/pre>\n\n\n\n<p>Both commands should now report the version you selected.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Configure Java for Common Applications<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Apache Maven<\/h3>\n\n\n\n<p>Maven reads <code>JAVA_HOME<\/code> to locate the JDK. If you set it in <code>\/etc\/profile.d\/java.sh<\/code> as described above, Maven will pick it up automatically. Install Maven with:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install -y maven<\/code><\/pre>\n\n\n\n<p>Verify it detects Java 21:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mvn -version<\/code><\/pre>\n\n\n\n<p>The output should show <code>Java version: 21.x.x<\/code> under the runtime information.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Gradle<\/h3>\n\n\n\n<p>Gradle also uses <code>JAVA_HOME<\/code>. If you are installing Gradle manually (not through dnf), download it from the official site and extract it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>wget https:\/\/services.gradle.org\/distributions\/gradle-8.12-bin.zip\nsudo mkdir -p \/opt\/gradle\nsudo unzip -d \/opt\/gradle gradle-8.12-bin.zip\nexport PATH=\/opt\/gradle\/gradle-8.12\/bin:$PATH<\/code><\/pre>\n\n\n\n<p>Verify:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gradle -version<\/code><\/pre>\n\n\n\n<p>Check that the JVM line shows Java 21.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Apache Tomcat<\/h3>\n\n\n\n<p>Tomcat 10.1.x and 11.x both support Java 21. If you install Tomcat from a tarball, set <code>JAVA_HOME<\/code> in the Tomcat service file or in <code>\/opt\/tomcat\/bin\/setenv.sh<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat &lt;&lt; 'EOF' | sudo tee \/opt\/tomcat\/bin\/setenv.sh\nexport JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))\nEOF\nsudo chmod +x \/opt\/tomcat\/bin\/setenv.sh<\/code><\/pre>\n\n\n\n<p>If you are using a systemd unit file for Tomcat, you can add the environment variable there instead:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>[Service]\nEnvironment=\"JAVA_HOME=\/usr\/lib\/jvm\/java-21-openjdk\"<\/code><\/pre>\n\n\n\n<p>Then reload and restart:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl daemon-reload\nsudo systemctl restart tomcat<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">java command not found after installation<\/h3>\n\n\n\n<p>If you get <code>-bash: java: command not found<\/code> right after installing, log out and log back in, or source the profile manually:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>source \/etc\/profile.d\/java.sh<\/code><\/pre>\n\n\n\n<p>If the file does not exist yet, check that the java binary is in the PATH:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>which java\nls -la \/usr\/bin\/java<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Wrong Java version is active<\/h3>\n\n\n\n<p>If <code>java -version<\/code> shows an older version, another Java is taking priority. Check what alternatives are registered:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo alternatives --config java<\/code><\/pre>\n\n\n\n<p>Select the Java 21 entry. Also check if something in your shell profile is overriding the PATH:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>which -a java<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">JAVA_HOME is not set or points to the wrong version<\/h3>\n\n\n\n<p>Verify the current value:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>echo $JAVA_HOME<\/code><\/pre>\n\n\n\n<p>If it is empty or incorrect, re-create <code>\/etc\/profile.d\/java.sh<\/code> as shown in the JAVA_HOME section above, then source it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">javac not found but java works<\/h3>\n\n\n\n<p>This means you installed the JRE (<code>java-21-openjdk<\/code>) but not the JDK. Install the development package:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install -y java-21-openjdk-devel<\/code><\/pre>\n\n\n\n<p>Then verify:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>javac -version<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Adoptium repository not working<\/h3>\n\n\n\n<p>If dnf fails to fetch packages from the Adoptium repo, check that the repo file is correct:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/etc\/yum.repos.d\/adoptium.repo<\/code><\/pre>\n\n\n\n<p>Make sure the <code>baseurl<\/code> contains <code>$releasever<\/code> (which resolves to 10 on RHEL 10). If Adoptium has not yet published packages for RHEL 10 specifically, you can try using the RHEL 9 path temporarily:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>baseurl=https:\/\/packages.adoptium.net\/artifactory\/rpm\/rhel\/9\/$basearch<\/code><\/pre>\n\n\n\n<p>Then clear the cache and retry:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf clean all\nsudo dnf install -y temurin-21-jdk<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Permission denied errors<\/h3>\n\n\n\n<p>All installation commands require root or sudo. If you are running as a non-root user, prefix commands with <code>sudo<\/code>. If sudo is not configured for your user, ask your system administrator to add you to the <code>wheel<\/code> group:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo usermod -aG wheel yourusername<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<p>You now have Java 21 LTS installed and configured on your RHEL 10, Rocky Linux 10, or AlmaLinux 10 system. Whether you went with the AppStream OpenJDK package or Eclipse Temurin, the end result is a production-ready Java 21 environment. With <code>JAVA_HOME<\/code> set in <code>\/etc\/profile.d\/java.sh<\/code> and the alternatives system configured, your Java setup will work correctly with Maven, Gradle, Tomcat, and any other Java-dependent tools you need to run.<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>Java 21 is the latest long-term support (LTS) release from Oracle and the OpenJDK community, with support guaranteed until at least September 2029. If you are running production workloads on RHEL 10, Rocky Linux 10, or AlmaLinux 10, this is the version you should be deploying. It brings virtual threads, pattern matching improvements, and a &#8230; <a title=\"Install Java 21 LTS (OpenJDK) on RHEL 10 \/ Rocky Linux 10 \/ AlmaLinux 10\" class=\"read-more\" href=\"https:\/\/computingforgeeks.com\/install-java-rhel-rocky-almalinux\/\" aria-label=\"Read more about Install Java 21 LTS (OpenJDK) on RHEL 10 \/ Rocky Linux 10 \/ AlmaLinux 10\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":4576,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[299,17,690,29,50,73],"tags":[311],"cfg_series":[],"class_list":["post-16236","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to","category-centos","category-dev","category-fedora","category-linux-tutorials","category-rhel","tag-java"],"_links":{"self":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/16236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/comments?post=16236"}],"version-history":[{"count":2,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/16236\/revisions"}],"predecessor-version":[{"id":164122,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/posts\/16236\/revisions\/164122"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media\/4576"}],"wp:attachment":[{"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/media?parent=16236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/categories?post=16236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/tags?post=16236"},{"taxonomy":"cfg_series","embeddable":true,"href":"https:\/\/computingforgeeks.com\/wp-json\/wp\/v2\/cfg_series?post=16236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}