Install Java 18 in Debian 11/Debian 10

This tutorial is going to take you through on how to Install Java 18 in in Debian 11/Debain 10. Java is a high-level, object-oriented programming language with few implementation requirements. It’s a general-purpose programming language that allows programmers to write once and run anywhere, which implies that compiled Java code may run on any platform that supports Java without being recompiled. Java programs are often compiled to byte code, which may run on any Java virtual machine (JVM), regardless of computer architecture.

The following are some of Java 18’s new features;

  • 400:UTF-8 by Default
  • 408:Simple Web Server
  • 413:Code Snippets in Java API Documentation]
  • 416:Reimplement Core Reflection with Method Handles
  • 417:Vector API (Third Incubator)
  • 418:Internet-Address Resolution SPI
  • 419:Foreign Function & Memory API (Second Incubator)
  • 420:Pattern Matching for switch (Second Preview)
  • 421:Deprecate Finalization for Removal

We are going to Install Java 18 in Debian 11/Debian 10 using the following methods;

How to Install Java 18 in Debian 11/Debian 10

Ensure that the system is up to date. To update and upgrade your system, use the command below.

sudo apt update && sudo apt upgrade -y

Install Java 18 in Debian 11/Debian 10 using OpenJDK Archive

  • Start by downloading JDK-18 archive using wget command.
wget https://download.java.net/java/GA/jdk18/43f95e8614114aeaa8e8a5fcf20a682d/36/GPL/openjdk-18_linux-x64_bin.tar.gz
  • Next extract the downloaded archive file.
sudo tar xvf openjdk-18_linux-x64_bin.tar.gz
  • Then move the extracted directory to /opt/ directory.
sudo mv jdk-18/ /opt/
  • Use the commands below, set the environment variables.
echo 'export JAVA_HOME=/opt/jdk-18' | tee -a ~/.bashrc
echo 'export PATH=$PATH:$JAVA_HOME/bin '|tee -a ~/.bashrc
source ~/.bashrc
  • Confirm JDK 18 is installed.
java --version

Sample output

openjdk 18 2022-03-22
OpenJDK Runtime Environment (build 18+36-2087)
OpenJDK 64-Bit Server VM (build 18+36-2087, mixed mode, sharing)

Install Java 18 in Debian 11/Debian 10 using DEB Binary Package

  • Download the .deb installer package.
wget https://download.oracle.com/java/18/latest/jdk-18_linux-x64_bin.deb
  • Then install it.
sudo apt install ./jdk-18_linux-x64_bin.deb

Sample output

Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'jdk-18' instead of './jdk-18_linux-x64_bin.deb'
The following additional packages will be installed:
  libc6-i386 libc6-x32
The following NEW packages will be installed:
  jdk-18 libc6-i386 libc6-x32
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 5,504 kB/162 MB of archives.
After this operation, 348 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 /home/kigz/jdk-18_linux-x64_bin.deb jdk-18 amd64 18-ga [156 MB]
  • Next set environmental variable.
export JAVA_HOME=/usr/lib/jvm/jdk-18
export PATH=$PATH:$JAVA_HOME/bin
  • Confirm JDK 18 is installed.
java --version

Test the Java Installation in Debian 11/Debian 10

  • Create sample java program using the command below.
sudo nano demo.java

Then paste the sample code below.

public class hello {
  public static void main(String[] args) {
    System.out.println("Hello World from itnixpro!");
  }
}
  • Compile and run the code using the following command.
java demo.java
  • The program should print the output below.
Hello World from itnixpro!
  • You have successfully installed Java 18 in Debian 11/Debian 10, Congratulations. This marks the end of our article.

Read more on Java 18 Documentation

Other Tutorials

Install Snipe-IT on Ubuntu 22.04

Install cockpit on Ubuntu 22.04

Synchronize Files between multiple devices using Syncthing

System administrator | Software Developer | DevOps

Leave a Comment