Install OpenJDK 19 on Rocky Linux 8: Free JDK – OrcaCore
This guide provides a comprehensive walkthrough on how to Install OpenJDK 19 on Rocky Linux 8. OpenJDK 19 is a production-ready and open-source distribution of Java Development Kit (JDK) version 19, released on September 20th, 2022. JDK 19 is a scheduled update following Oracle’s 6-month release cycle. It doesn’t introduce breaking changes, with most features still in the incubator and preview phases. Follow the steps below to set up OpenJDK 19 on Rocky Linux 8, as demonstrated on the Orcacore website.
To download and Install OpenJDK 19 on Rocky Linux 8, you need to be logged into your server as a non-root user with sudo privileges. You can achieve this by following our guide on Initial Server Setup with Rocky Linux 8.
1. OpenJDK 19 Setup on Rocky Linux 8
First, update your local package index using the following command:
sudo dnf update -y
Next, install the necessary packages using the command below:
sudo dnf install curl wget tar -y
Download OpenJDK 19
Visit the JDK Downloads page to download the latest OpenJDK 19 archive using the wget command:
sudo wget https://download.java.net/java/GA/jdk19.0.1/afdd2e245b014143b62ccb916125e3ce/10/GPL/openjdk-19.0.1_linux-x64_bin.tar.gz
Extract the downloaded file:
sudo tar xvf openjdk-19.0.1_linux-x64_bin.tar.gz
Move the extracted file to the /opt
directory:
sudo mv jdk-19.0.1 /opt/
Configure Java Environment Path
Configure the Java home path using the following command:
sudo tee /etc/profile.d/jdk19.sh <<EOF
export JAVA_HOME=/opt/jdk-19.0.1
export PATH=$PATH:$JAVA_HOME/bin
EOF
Source your profile file:
source /etc/profile.d/jdk19.sh
Verify your Java Home path:
echo $JAVA_HOME
Output
/opt/jdk-19.0.1
You can also verify your Java 19 installation on Rocky Linux 8 by checking its version:
java -version

2. Set up Java SE Development Kit 19 on Rocky Linux 8
Alternatively, you can Install OpenJDK 19 on Rocky Linux 8 through the Java SE Development Kit 19. If you choose to go with Java SE Development Kit 19, download the RPM package for CentOS / RHEL / Fedora systems:
sudo wget https://download.oracle.com/java/19/latest/jdk-19_linux-x64_bin.rpm
Install the RPM package using the yum or rpm command:
sudo rpm -Uvh jdk-19_linux-x64_bin.rpm

Confirm the Java installation on Rocky Linux 8:
java -version
Output
openjdk version "19.0.2" 2022-10-18
OpenJDK Runtime Environment (build 19.0.2+10-21)
OpenJDK 64-Bit Server VM (build 19.0.2+10-21, mixed mode, sharing)
Configure the Java environment:
cat <<EOF | sudo tee /etc/profile.d/jdk.sh
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
3. Create a Sample Project with OpenJDK 19
This section demonstrates how to create a sample project to verify that your Java 19 installation is working correctly on Rocky Linux 8.
Create and open the hello world file with your favorite text editor (e.g., vi):
vi HelloWorld.java
Add the following content to the file:
public class HelloWorld {
public static void main(String[] args) {
// Prints "Hello, World" to the terminal window.
System.out.println("Hello, World");
}
}
Save and close the file.
Compile and run your Java code:
java HelloWorld.java
Output
Hello, World
That’s it! You’re done.
Conclusion
OpenJDK 19 provides the necessary tools, libraries, and runtime to develop and run Java applications. You have now successfully learned how to Install OpenJDK 19 (Java 19) on Rocky Linux 8.
Hope you enjoyed this guide. You may also find these guides helpful:
- PostgreSQL 15 For Rocky Linux 8
- How To Install Yarn on Rocky Linux 8
- Install Latest PostgreSQL on Rocky Linux 8
- Nginx Web Server Setup Rocky Linux 8
- Nodejs Setup Rocky Linux 8
- Ntopng Monitoring For Rocky Linux 8
Alternative Solutions for Installing OpenJDK 19 on Rocky Linux 8
While the above methods are perfectly valid, here are two alternative approaches to installing OpenJDK 19 on Rocky Linux 8, providing greater flexibility and potentially simplifying the process. These involve using alternative package managers or leveraging containerization.
1. Using SDKMAN! (Software Development Kit Manager)
SDKMAN! is a tool designed to manage multiple versions of Software Development Kits, including Java. This allows for easy switching between different JDK versions, which can be invaluable for development environments requiring specific Java versions. This is another way you can Install OpenJDK 19 on Rocky Linux 8.
Installation and Usage:
-
Install SDKMAN!: Open a terminal and execute the following command:
curl -s "https://get.sdkman.io" | bash
Follow the on-screen instructions to complete the installation. You’ll likely need to open a new terminal or source your shell profile for SDKMAN! to be available.
-
List Available Java Versions: After SDKMAN! is installed, you can list the available Java versions using:
sdk list java
This will display a list of available JDKs, including various OpenJDK builds.
-
Install OpenJDK 19: Identify the appropriate OpenJDK 19 build from the list (e.g., a build from Liberica, GraalVM, or a specific vendor). Let’s assume you want to install Liberica OpenJDK 19. The command would be similar to:
sdk install java 19.0.1-librca
Replace
19.0.1-librca
with the actual identifier for the desired OpenJDK 19 build. SDKMAN! will download, install, and configure the JDK for you. -
Set as Default (Optional): If you want OpenJDK 19 to be the default Java version, use:
sdk default java 19.0.1-librca
-
Verify Installation: As before, verify the installation with:
java -version
Benefits of SDKMAN!:
- Version Management: Easily switch between different Java versions.
- Clean Installation: SDKMAN! manages the installation and environment variables, reducing the risk of conflicts.
- Vendor Choice: Provides access to JDK builds from various vendors.
2. Using a Container (Docker)
Containerization, using tools like Docker, provides a completely isolated environment for running Java applications. This eliminates dependency conflicts and ensures consistent behavior across different systems. Using docker is another way you can Install OpenJDK 19 on Rocky Linux 8.
Installation and Usage:
-
Install Docker: If Docker is not already installed on your Rocky Linux 8 system, install it using the following commands:
sudo dnf install docker-ce --nobest -y sudo systemctl start docker sudo systemctl enable docker
-
Pull an OpenJDK 19 Docker Image: Docker Hub hosts numerous pre-built OpenJDK images. Pull the official OpenJDK 19 image:
docker pull openjdk:19
-
Run a Container: Run a container based on the pulled image:
docker run -it openjdk:19 bash
This command starts a container in interactive mode, providing you with a bash shell inside the container.
-
Verify Java Version (Inside the Container): Inside the container’s shell, verify the Java version:
java -version
-
Mount a Volume (For Development): To develop Java applications outside the container and run them inside, mount a local directory as a volume:
docker run -it -v /path/to/your/project:/app openjdk:19 bash
Replace
/path/to/your/project
with the actual path to your project directory. Now, you can compile and run Java code within the container, accessing the files from your local machine. For example, if you have aHelloWorld.java
file in your project directory:javac /app/HelloWorld.java java -cp /app HelloWorld
Benefits of Docker:
- Isolation: Guarantees consistent application behavior, regardless of the host system.
- Reproducibility: Easily recreate the same environment on different machines.
- Dependency Management: Eliminates dependency conflicts.
- Simplified Deployment: Simplifies the deployment process.
Code Example (Dockerfile):
A Dockerfile
automates the process of building a Docker image with OpenJDK 19 and your application. Here’s an example:
FROM openjdk:19
WORKDIR /app
COPY . .
RUN javac HelloWorld.java
CMD ["java", "HelloWorld"]
To build and run this image:
- Save the above content as
Dockerfile
in your project directory (whereHelloWorld.java
resides). - Build the image:
docker build -t my-java-app .
- Run the container:
docker run my-java-app
This approach encapsulates the entire Java environment and application within a container, making deployment and management significantly easier. You can successfully Install OpenJDK 19 on Rocky Linux 8 using this approach.