blog-image

May 27, 2024

9 min read

How To Install Java and its Virtual Machine on Debian 11

Written by

Abdelhadi Dyouri

Java is a high-level, object-oriented programming language. The JVM or Java’s virtual machine, is a virtual machine that enables a computer to run Java and programs that are written in a language that can be compiled to Java bytecode such as Scala and Kotlin programs. Java and JVM are required for many DevOps tools such as Jenkins, Cassandra, and Apache Tomcat.

In this tutorial, you will learn how to install the Java Runtime Environment (JRE) and the Java Developer Kit (JDK) using apt. The JDK provides software tools to develop Java programs. The JRE executes the programs you write in Java. In this tutorial, you will install OpenJDK, which is an open-source implementation of Java. However, you can also install the Oracle JDK, which is the original version. Both OpenJDK and OracleJDK are developed and maintained by Oracle, the developers of Java, and both are functionally identical since Java 11.

Prerequisites

  • Basic knowledge of the Linux command line.
  • An Debian 11 server with a non-root user with sudo privileges. You can get affordable, and powerful Debian 11 servers from our website, and you can check out our How to access your server using SSH guide to learn how to access your server and create a sudo user.

Updating the Package Cache

Start by updating the packages in the package manager cache to the latest available versions using the following command:

sudo apt update

Installing the JRE/JDK using Apt

To install the JRE from the OpenJDK version of Java, use the following command:

sudo apt install default-jre

This will install the default JRE in the Debian repositories, and will allow you to execute Java programs.

Once the installation is finished, check your Java version to ensure that the JRE was successfully installed:

java -version

You should receive an output similar to the following:

openjdk version "11.0.18" 2023-01-17
OpenJDK Runtime Environment (build 11.0.18+10-post-Debian-1deb11u1)
OpenJDK 64-Bit Server VM (build 11.0.18+10-post-Debian-1deb11u1, mixed mode, sharing)

Next, install the JDK to compile and run some Java software that requires it. To do so, use the following command:

sudo apt install default-jdk

To ensure that the JDK is successfully installed, check the version of the Java compiler javac:

javac -version

You should receive an output

Continue reading this article
by subscribing to our newsletter.
Subscribe now

A note about tutorials: We encourage our users to try out tutorials, but they aren't fully supported by our team—we can't always provide support when things go wrong. Be sure to check which OS and version it was tested with before you proceed.

If you want a fully managed experience, with dedicated support for any application you might want to run, contact us for more information.

Leave a Reply