JDK 11
Ubuntu
Installation Guide
Java Development Kit
Linux Operating System

How to install JDK 11 under Ubuntu?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

JDK 11 is still a common baseline for enterprise Java applications, build pipelines, and long-lived services. On Ubuntu, the simplest install path is usually through apt, but a reliable setup also needs verification, alternatives, and a correct JAVA_HOME.

Check What Is Already Installed

Before changing anything, inspect the current Java state:

bash
java -version || true
javac -version || true
update-alternatives --list java 2>/dev/null || true

If java exists but javac does not, you probably have only a runtime and not the full JDK.

Then refresh package metadata:

bash
sudo apt update

Install OpenJDK 11 with apt

On Ubuntu releases that still ship OpenJDK 11 in the configured repositories, install it with:

bash
sudo apt install openjdk-11-jdk

Then verify:

bash
java -version
javac -version

For development machines and build agents, install the full JDK rather than only the JRE.

Set the Active Java Version

If multiple Java versions are installed, configure the active alternatives explicitly:

bash
sudo update-alternatives --config java
sudo update-alternatives --config javac

Then confirm both commands now point to version 11:

bash
1java -version
2javac -version
3readlink -f "$(which java)"
4readlink -f "$(which javac)"

It is common to switch java and forget javac, which creates confusing compile behavior later.

Set JAVA_HOME

Many tools such as Maven, Gradle, and IDE integrations rely on JAVA_HOME.

You can derive it from the active compiler path:

bash
dirname "$(dirname "$(readlink -f "$(which javac)")")"

Then add it to your shell profile:

bash
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH="$JAVA_HOME/bin:$PATH"

Reload the shell:

bash
source ~/.bashrc

Or update ~/.zshrc if you use zsh.

Run a Real Smoke Test

Version output is helpful, but compiling a file is better proof that the toolchain is usable:

bash
1cat > Main.java <<'JAVA'
2public class Main {
3    public static void main(String[] args) {
4        System.out.println("JDK 11 installed");
5    }
6}
7JAVA
8
9javac Main.java
10java Main

This catches path and environment mistakes that java -version alone may not reveal.

What If openjdk-11-jdk Is Not Available

Some Ubuntu versions may not expose the package in the repositories you currently have enabled. In that case, the right next step is not random internet scripts. First confirm:

  • the Ubuntu release you are on
  • the configured repositories
  • whether your team wants distro packages or a vendor distribution

If the package is unavailable, many teams use a supported vendor build of JDK 11, but the important point is to choose one installation source deliberately and document it consistently across local machines and CI.

CI and Team Consistency

For shared development and build environments, standardize verification commands:

bash
1java -version
2javac -version
3./mvnw -v || true
4./gradlew -v || true

If you need high reproducibility, pin the JDK in a container or base image rather than relying on whichever Java version happens to be active on a host.

Common Pitfalls

  • Installing default-jdk and assuming it always means Java 11.
  • Switching the java alternative but forgetting javac.
  • Setting JAVA_HOME to the wrong architecture-specific path copied from another machine.
  • Editing the shell profile but forgetting to reload it.
  • Verifying only the version output and skipping an actual compile test.

Summary

  • Install OpenJDK 11 with apt when your Ubuntu repositories provide openjdk-11-jdk.
  • Check existing Java state before making changes.
  • Set both java and javac alternatives explicitly if multiple versions are installed.
  • Configure and verify JAVA_HOME for build tools.
  • Use a real compile-and-run smoke test to confirm the installation is actually usable.

Course illustration
Course illustration

All Rights Reserved.