In our today’s guide, we are going to look at how to install Java 17 (OpenJDK 17) on Oracle Linux. What is java and what is it used for? Java is a programming language and a computing platform. You will find many powerful Enterprise applications written in Java. It is also required in our computers in order for some applications to run. Android applications are basically build with Java.
OpenJDK is the Java development environment. It is free to download and install. JDK 17 is the open-source reference implementation of version 17 of the Java SE Platform as specified by JSR 389. A significant number of Java Enhancement Proposals (JEPs) have been released in version 17 as listed below:
- Restore Always-Strict Floating-Point Semantics
- macOS/AArch64 Port
- Enhanced Pseudo-Random Number Generators
- New macOS Rendering Pipeline
- Strongly Encapsulate JDK Internals
- Deprecate the Applet API for Removal
- Context-Specific Deserialization Filters
- Pattern Matching for switch (Preview)
- Remove RMI Activation
- Remove the Experimental AOT and JIT Compiler
- Sealed Classes
- Foreign Function & Memory API (Incubator)
- Deprecate the Security Manager for Removal
- Vector API (Second Incubator)
Option 1: Install OpenJDK 17 on Oracle Linux 8
You can install OpenJDK 17 from OS default repositories.
sudo yum install java-17-openjdk java-17-openjdk-devel
After the installation confirm Java version.
$ 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)
Option 2: Install Java SE 17 on Oracle Linux 8
If you wish to install Java SE Development Kit 17 instead, go ahead to download RPM package for Oracle Linux 8 from Oracle java download page. Download the rpm :
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.rpm
Then install it by running the below commands:
sudo rpm -Uvh jdk-17_linux-x64_bin.rpm
Now confirm Java installed version.
$ java -version
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-ga ################################# [100%]
Configure Java environment.
sudo tee /etc/profile.d/jdk.sh <<EOF
export JAVA_HOME=/usr/java/default
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
To use Java Home, source the file.
source /etc/profile.d/jdk.sh
Test Java Installation
To test our Java installation, let us create a simple html file. Create a file test.java with the content as shown below:
$ vi HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println(“Hello, world”);
}
}
Compile Java code.
java HelloWorld.java
Now run your java program.
$ java HelloWorld
Hello, world
Set default Java Version
Run the command below to choose your default java version.
sudo alternatives –config java
Key in the number for your chosen version and press Enter
There is 1 program that provides 'java'.
Selection Command
-----------------------------------------------
*+ 1 /usr/java/jdk-17/bin/java
Enter to keep the current selection[+], or type selection number:
Explore More with CloudSpinx
Looking to streamline your tech stack? At CloudSpinx, we deliver the best solutions for your IT ventures.
Check out more articles: