Friday, January 10, 2025
Google search engine
HomeGuest BlogsInstall Oracle Java 18 (OpenJDK 18) on Ubuntu / Debian

Install Oracle Java 18 (OpenJDK 18) on Ubuntu / Debian

.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}}

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.

.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}}

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:

.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