Install OpenJDK 19 on Centos 7

In this tutorial, we want to teach you to Install OpenJDK 19 (Java 19) on Centos 7.

OpenJDK is a free, open-source version of the Java Development Kit for the Java Platform, Standard Edition (Java SE). OpenJDK, which stands for Open Java Development Kit, originated from an effort initiated by Sun Microsystems in 2006 and is now sponsored and led by Oracle. The project is licensed under the GNU General Public License (GNU GPL) version 2 with a linking exception. Without the linking exception, components that linked to the Java class library would be subject to the terms of the GPL license.

Steps To Install OpenJDK 19 (Java 19) on Centos 7

To complete this guide, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Centos 7.

Install Java 19 on Centos 7

First, you need to update your local package index with the command below:

sudo yum update -y

Then install the required packages by using the following command:

sudo yum install curl wget -y

Download OpenJDK 19

At this point, you need to visit the JDK Downloads page to download the latest archive by 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

Then, extract your downloaded file with the command below:

sudo tar xvf openjdk-19.0.1_linux-x64_bin.tar.gz

Next, move your extracted file to the /opt directory:

sudo mv jdk-19.0.1 /opt/

Configure Java Environment Path

At this point, you need to configure the Java home path by 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 with the following command:

source /etc/profile.d/jdk19.sh

Verify your Java Home path:

echo $JAVA_HOME
Output
/opt/jdk-19.0.1

Also, you can verify your Java installation by checking its version:

java -version
Output
openjdk version "19.0.1" 2022-10-18
OpenJDK Runtime Environment (build 19.0.1+10-21)
OpenJDK 64-Bit Server VM (build 19.0.1+10-21, mixed mode, sharing)

Install Java SE Development Kit 19 on Centos 7

If you choose to go with Java SE Development Kit 19, download the RPM package for CentOS / RHEL / Fedora system using the command below:

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

Then, install the RPM package using the yum or rpm command:

sudo rpm -Uvh jdk-19_linux-x64_bin.rpm
Output
warning: jdk-19_linux-x64_bin.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:jdk-19-2000:19.0.2-7             ################################# [100%]

Confirm the Java installation on Centos 7:

java -version
Output
openjdk version "19.0.1" 2022-10-18
OpenJDK Runtime Environment (build 19.0.1+10-21)
OpenJDK 64-Bit Server VM (build 19.0.1+10-21, mixed mode, sharing)

Configure the Java environment with the command below:

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 by using the following command:

source /etc/profile.d/jdk.sh

Create a sample project with Java 19

At this point, we will show you to create a sample project to see that your Java 19 is working correctly on Centos 7.

Create and open the hello world file with your favorite text editor, here we use vi editor:

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");
    }

}

When you are done, save and close the file.

Then, compile and run your Java code:

java HelloWorld.java
Output
Hello, World

That’s it, you are done.

Conclusion

At this point, you have learned to Install OpenJDK 19 (Java 19) on Centos 7.

Hope you enjoy it. You may be like these guides on the Orcacore website:

Install Git on Centos 7

Enable RPM Fusion Repository on Centos 7

Add Swap on Centos 7

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Stay informed and not overwhelmed, subscribe now!