Install Java 17 (OpenJDK 17) on AlmaLinux / Rocky 8

Java is a high-level object-oriented programming language and computing platform intended to let application developers write once and run everywhere. This means that, a compiled java code runs on all platforms that support Java without need for recompilation. JDK is a collection of various programming tools such as JRE(Java Runtime Environment), Java, Javac, Jar and many others. In this guide, we will walk through how to install Java 17 (OpenJDK 17) on Rocky Linux / AlmaLinux / CentOS Stream 8.

It has the following features.

  • New rendering pipeline for MacOS, using the Apple Metal API as an alternative to the existing pipeline that uses the deprecated OpenGL API
  • Porting the JDK to MacOS/AArch64 in response to Apple’s plan to transition its Macintosh computers from x64 to AArch64
  • Enhanced pseudo-random number generators
  • Sealed classes and interfaces restrict which other classes or interfaces may extend or implement them.
  • The foreign function and memory API which allows Java programs to interoperate with code and data outside of the Java runtime
  • Removal of the Remote Method Invocation (RMI) Activation mechanism
  • Strong encapsulation for JDK internals
  • Deprecation of the Security Manager, preparing for removal in a future release
  • Context-specific deserialization filters
  • Deprecate the Applet API for Removal
  • Remove the Experimental AOT and JIT Compiler
  • Among many other new features and improvements

We will cover a few methods to get Java 17 installed:

  1. OpenJDK
  2. Oracle JDK/JRE.

1) Install OpenJDK 17 on AlmaLinux / Rocky Linux 8

Java OpenJDK 17 is an open source implementation of Java SE platform. OpenJDK is available on the RHEL 8 for x86_64 – AppStream repositories:

Update your cache.

sudo yum -y makecache

Then proceed to install OpenJDK 17 locally in your system:

sudo yum install java-17-openjdk java-17-openjdk-devel

Verify the Java installation.

$ java --version
openjdk 17.0.11 2024-04-16 LTS
OpenJDK Runtime Environment (Red_Hat-17.0.11.0.9-3) (build 17.0.11+9-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.11.0.9-3) (build 17.0.11+9-LTS, mixed mode, sharing)

2) Install Oracle JDK 17 on Rocky 8 / AlmaLinux 8

Here we download the production ready OpenJDK from the Java SE Downloads page. Alternatively, one can use the Wget command as below but remember login is required upon visiting the official page. After login, obtain the download URL and use it as below.

wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm

Then install the ,rpm file.

sudo rpm -ivh jdk-17_linux-x64_bin.rpm

sample output.

warning: jdk-17_linux-x64_bin.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:jdk-17-2000:17.0.2-ga            ################################# [100%]

By default, Java is installed in /usr/java/ directory. However you can install Java in a custom path using.

sudo rpm -ivh –prefix=// .rpmfile

Validate installation of Java 17 on Rocky Linux 8 / CentOS 8 / CentOS 7:

$ java -version
java version "17.0.12" 2024-07-16 LTS
Java(TM) SE Runtime Environment (build 17.0.12+8-LTS-286)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.12+8-LTS-286, mixed mode, sharing)

$ javac -version
javac 17.0.12

Set Java home:

$ sudo vi /etc/profile
export JAVA_HOME=/usr/java/default
$ source /etc/profile
$ echo $JAVA_HOME
/usr/java/default

3) Set Default Java Version

With multiple Java versions installed on your system, you can set the default one with the following steps:

First list the available versions:

sudo alternatives --config java

In the output, you should see the versions installed on your system.

There are 3 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
   1           java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.23.0.9-3.el8.x86_64/bin/java)
*+ 2           /usr/lib/jvm/jdk-17.0.12-oracle-x64/bin/java
   3           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.412.b08-2.el8.x86_64/jre/bin/java)

Enter to keep the current selection[+], or type selection number: 2

Select your desired version by entering the number as above.

Now verify the set version using:

$ java -version
java version "17.0.12" 2024-07-16 LTS
Java(TM) SE Runtime Environment (build 17.0.12+8-LTS-286)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.12+8-LTS-286, mixed mode, sharing)

4) Set the JAVA_HOME Environment

The JAVA_HOME environment variable is used by some Java applications to determine the install location of Java and the version to use in running the application.

Here we want to set a persistent path. We will edit the file in /etc/profile.d directory.

sudo vi /etc/profile

In the file, add this line.

JAVA_HOME="/path/to/java/install"

For the set changes to take effect, we either log out and login or use the source command as below:

source /etc/profile

Verify if the variable was set correctly by executing:

$ echo $JAVA_HOME
/usr/java/default

5) Test Java Installation

With Java installed successfully, let’s test it by creating a simple HTML file.

Create the file with the name Hello_World.java with the message as below:

cat > Hello_World.java <<EOF
public class helloworld {
  public static void main(String[] args) {
    System.out.println("Hello Java World from Kenya!");
  }
}
EOF

Compile the code.

java Hello_World.java

Sample Output:

$ java Hello_World.java
Hello Java World from Kenya!

Conclusion

We have come to the end of our Guide. I have demonstrated the two ways to get Java 17 LTS Installed on Rocky / CentOS / AlmaLinux 8, configuring and setting the default Java version for your system.

Explore More with CloudSpinx

Looking to streamline your tech stack? Visit CloudSpinx, for a comprehensive consult on any of the major IT sectors.

Check out our other articles:

Your IT Journey Starts Here!

Ready to level up your IT skills? Our new eLearning platform is coming soon to help you master the latest technologies.

Be the first to know when we launch! Join our waitlist now.

Join our Linux and open source community. Subscribe to our newsletter for tips, tricks, and collaboration opportunities!

Recent Post

Leave a Comment

Your email address will not be published. Required fields are marked *

Related Post

PHP is a recursive acronym that stands for Hypertext Processor. It is a popular general-purpose scripting language used in web […]

We previously installed Asterisk LTS 18 on Rocky Linux 9 and we saw that it can only be administered from […]

In this blog post we will install Asterisk 18 with FreePBX on Rocky Linux / AlmaLinux 9. Asterisk is a […]

Let's Connect

Unleash the full potential of your business with CloudSpinx. Our expert solutions specialists are standing by to answer your questions and tailor a plan that perfectly aligns with your unique needs.
You will get a response from our solutions specialist within 12 hours
We understand emergencies can be stressful. For immediate assistance, chat with us now

Contact CloudSpinx today!

Download CloudSpinx Profile

Discover the full spectrum of our expertise and services by downloading our detailed Company Profile. Simply enter your first name, last name, and email address.