Installing the Java Development Kit (JDK) on Ubuntu should use Ubuntu's OpenJDK packages unless a project vendor requires another distribution. The package-managed path adds javac for compiling Java code and java for running it, with updates delivered through APT.
The default-jdk meta-package follows the Java release selected by the Ubuntu version. On Ubuntu 26.04 LTS it installs OpenJDK 25, while older supported Ubuntu releases can point to another default without changing the install command.
Use default-jdk for a full desktop-capable JDK, or default-jdk-headless on servers and CI runners that do not need GUI Java libraries. Install a named package such as openjdk-21-jdk only when a project requires that Java release, then change the default separately if more than one version is installed.
Steps to install JDK on Ubuntu:
- Refresh the local APT package lists.
$ sudo apt update
- Install Ubuntu's default JDK package.
$ sudo apt install default-jdk
On servers, containers, and CI runners that do not need desktop Java libraries, install default-jdk-headless instead. If a project requires a named Java release, use a package such as openjdk-21-jdk after confirming it exists for the Ubuntu release with apt show openjdk-21-jdk.
- Confirm that the compiler command is installed.
$ command -v javac /usr/bin/javac
- Check the installed compiler version.
$ javac -version javac 25.0.3
- Check the runtime version that will launch Java programs.
$ java -version openjdk version "25.0.3" 2026-04-21 OpenJDK Runtime Environment (build 25.0.3+9-2~26.04.2-Ubuntu) OpenJDK 64-Bit Server VM (build 25.0.3+9-2~26.04.2-Ubuntu, mixed mode, sharing)
The exact Java version and architecture suffix can differ by Ubuntu release, update pocket, and CPU architecture. The required proof is that both javac and java report the expected OpenJDK release. Change the default Java command separately only if more than one version is installed. Related: How to set the default Java version on Ubuntu
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.