How can I install Oracle Java 18 (OpenJDK 18) on Ubuntu / Debian Linux system?. Java is a popular programming language created in 1995 and used for developing mobile, web and Desktop Applications among many others. JDK 18 is an open-source reference implementation of version 18 of the Java SE Platform as specified by by JSR 393 in the Java Community Process. It is available for general use in Production environments.
For CentOS / Fedora, refer to: How To Install Oracle Java 18 (OpenJDK 18) on CentOS / Fedora
The Java Platform lets you develop and deploy Java applications on servers, desktops and IoT devices. This short guide will cover the steps required to Install Oracle Java 18 on Ubuntu & Debian Linux machine. To be specific, the OpenJDK 18 or Java SE Development Kit 18.
Option 1: Install OpenJDK 18 on Ubuntu / Debian
Install curl or wget downloader utility:
sudo apt update
sudo apt install -y curl wget
Visit JDK 18 releases page to download the latest archive.
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
openjdk version "18" 2022-03-22
OpenJDK Runtime Environment (build 18+36-2087)
OpenJDK 64-Bit Server VM (build 18+36-2087, mixed mode, sharing)
Option 2: Install Java SE Development Kit 18 on Ubuntu / Debian from .deb package
Java SE Development Kit comprises of a set of tools required by Developers to write, compile, run and debug Java Applications.
Update your list of packages and install curl/wget.
sudo apt update
sudo apt -y install wget curl
Download Java SE Development Kit 18 from releases downloads page.
wget https://download.oracle.com/java/18/latest/jdk-18_linux-x64_bin.deb
You can as well download the package manually. Once done install it by running the commands below:
sudo apt install ./jdk-18_linux-x64_bin.deb
Additional packages required as dependencies will be installed automatically.
The following additional packages will be installed:
libc6-i386 libc6-x32 libxi6 libxrender1 libxtst6 x11-common
The following NEW packages will be installed:
jdk-18 libc6-i386 libc6-x32 libxi6 libxrender1 libxtst6 x11-common
0 upgraded, 7 newly installed, 0 to remove and 65 not upgraded.
Need to get 5588 kB/162 MB of archives.
After this operation, 349 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Configure Java environment.
cat <<EOF | sudo tee /etc/profile.d/jdk18.sh
export JAVA_HOME=/usr/lib/jvm/jdk-18
export PATH=\$PATH:\$JAVA_HOME/bin
EOF
To check if you have Java installed on your machine, type the following command:
$ source /etc/profile.d/jdk18.sh
$ 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)
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 from Java 18");
}
}
EOF
Run your Java program.
$ java HelloWorld.java
Hello, World from Java 18
Recommended books:
More how to guides:
- How to set default Java version on Ubuntu / Debian
- Set JAVA_HOME on CentOS / RHEL / Fedora
- How to Install Apache Hadoop / HBase on Ubunt
- How to Install Java 8 on Ubuntu
- How to Install Apache Hadoop / HBase on CentOS 7