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.
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.
Recommended books:
Enjoy your Java Development.