How to Install Java JDK 18 on Ubuntu 22.04 / Ubuntu 20.04

Java 18 (Non-LTS) is the latest release for the Java SE platform. This newest release includes JDK 18, which provides an environment for developing applications using the Java programing language, testing, and running the Java programs.
Java JDK 18 is supported until September 2022. So, if you are looking for an LTS version, install Java JDK 17 on your Ubuntu system.
Here, we will see how to install Java JDK 18 on Ubuntu 22.04 / Ubuntu 20.04.
Install Java JDK on Ubuntu 22.04 / Ubuntu 20.04
Install OpenJDK 18 on Ubuntu 22.04 / 20.04
OpenJDK has separated packages for JDK (Java Development Kit) for developing Java applications and JRE (Java Runtime Environment) for running Java applications.
First, update the repository index.
sudo apt update
Then, install the OpenJDK or JRE package as per your requirements.
OpenJDK 18 JDK
sudo apt install -y openjdk-18-jdk
OpenJDK 18 JRE
sudo apt install -y openjdk-18-jre
Install Oracle JDK 18 On Ubuntu 22.04 / 20.04
First, install dependencies for Oracle JDK 18 installation.
sudo apt update sudo apt install -y libc6-x32 libc6-i386
Then, download Oracle Java JDK 18 using the wget
command in the terminal.
wget https://download.oracle.com/java/18/latest/jdk-18_linux-x64_bin.deb
Finally, install Oracle Java JDK 18 using the dpkg
command.
sudo dpkg -i jdk-18_linux-x64_bin.deb
In some cases, you may need to install Oracle JDK 18 on the PATH
location.
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-18/bin/java 1
Verify Java JDK Installation
After installing JDK, use the below command to verify the version.
java -version
Output:
java version "18.0.1" 2022-04-19 Java(TM) SE Runtime Environment (build 18.0.1+10-24) Java HotSpot(TM) 64-Bit Server VM (build 18.0.1+10-24, mixed mode, sharing
Conclusion
That’s All. I hope you have learned how to install Java JDK 18 on Ubuntu 22.04 / Ubuntu 20.04.