blog-image

Mar 14, 2023

9 min read

How To Install Java and its Virtual Machine on Ubuntu 22.04

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 Ubuntu 22.04 server with a non-root user with sudo privileges. You can get affordable, and powerful Ubuntu 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 Ubuntu 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.17" 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu222.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu222.04, 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
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.