Sunday, January 5, 2025
Google search engine
HomeGuest BlogsInstall Java 18 (OpenJDK 18) on CentOS/Fedora/Rocky Linux

Install Java 18 (OpenJDK 18) on CentOS/Fedora/Rocky Linux

.tdi_3.td-a-rec{text-align:center}.tdi_3 .td-element-style{z-index:-1}.tdi_3.td-a-rec-img{text-align:left}.tdi_3.td-a-rec-img img{margin:0 auto 0 0}@media(max-width:767px){.tdi_3.td-a-rec-img{text-align:center}}

Welcome today’s guide on how to install Java 18 on CentOS 7/6 & Fedora 31/30/29. Java 18 reached General Availability on 17 September 2019. Production-ready binaries are available from Oracle for Java SE Development Kit 18 on. This is the latest release of Java as of this writing.

JDK 18 is the open-source reference implementation of version 18 of the Java SE Platform as specified by by JSR 388 in the Java Community Process. Install JDK | OpenJDK 18 on your CentOS / Fedora/ Rocky / AlmaLinux system using the next steps.

Option 1: Install OpenJDK 18 on CentOS / Fedora / Rocky / AlmaLinux

Visit JDK 18 releases page to download the latest archive.

.tdi_2.td-a-rec{text-align:center}.tdi_2 .td-element-style{z-index:-1}.tdi_2.td-a-rec-img{text-align:left}.tdi_2.td-a-rec-img img{margin:0 auto 0 0}@media(max-width:767px){.tdi_2.td-a-rec-img{text-align:center}}

sudo yum install -y curl wget
curl -O https://download.java.net/java/GA/jdk18/43f95e8614114aeaa8e8a5fcf20a682d/36/GPL/openjdk-18_linux-x64_bin.tar.gz

Extract downloaded file using tar command.

tar xvf openjdk-18_linux-x64_bin.tar.gz

Move the resulting folder to /opt directory.

sudo mv jdk-18 /opt/

Configure Java environment:

sudo tee /etc/profile.d/jdk18.sh <<EOF
export JAVA_HOME=/opt/jdk-18
export PATH=\$PATH:\$JAVA_HOME/bin
EOF

Source your profile file and check java command

source /etc/profile.d/jdk18.sh

Confirm Java version.

$ echo $JAVA_HOME
/opt/jdk-18

$ java -version
java version "18" 2022-03-22
Java(TM) SE Runtime Environment (build 18+36-2087)
Java HotSpot(TM) 64-Bit Server VM (build 18+36-2087, mixed mode, sharing)

Option 2: Install Java SE Development Kit 18 on CentOS/Fedora/Rocky Linux

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

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

Install RPM package using the yum command.

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

Confirm Java version installed

$ java -version
java version "18" 2022-03-22
Java(TM) SE Runtime Environment (build 18+36-2087)
Java HotSpot(TM) 64-Bit Server VM (build 18+36-2087, mixed mode, sharing)

Configure Java environment.

cat <<EOF | sudo tee /etc/profile.d/jdk18.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/jdk18.sh

Test Java Installation

Create a HelloWorld Java program.

tee HelloWorld.java<<EOF 
public class HelloWorld {

    public static void main(String[] args) {
        // Prints "Hello, World" to the terminal window.
        System.out.println("Hello, World");
    }

}
EOF

Run your Java program.

$ java HelloWorld
Hello, World

Choosing Default Version of Java

If you have more than one version of Java installed, you can set default one using alternatives command.

sudo alternatives --config java

Select Java to set as default.

install java 13 centos fedora rhel

Recommended books:

Enjoy your Java Development.

.tdi_4.td-a-rec{text-align:center}.tdi_4 .td-element-style{z-index:-1}.tdi_4.td-a-rec-img{text-align:left}.tdi_4.td-a-rec-img img{margin:0 auto 0 0}@media(max-width:767px){.tdi_4.td-a-rec-img{text-align:center}}

RELATED ARTICLES

Most Popular

Recent Comments