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:
If java exists but javac does not, you probably have only a runtime and not the full JDK.
Then refresh package metadata:
Install OpenJDK 11 with apt
On Ubuntu releases that still ship OpenJDK 11 in the configured repositories, install it with:
Then verify:
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:
Then confirm both commands now point to version 11:
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:
Then add it to your shell profile:
Reload the shell:
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:
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:
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-jdkand assuming it always means Java11. - Switching the
javaalternative but forgettingjavac. - Setting
JAVA_HOMEto 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
11withaptwhen your Ubuntu repositories provideopenjdk-11-jdk. - Check existing Java state before making changes.
- Set both
javaandjavacalternatives explicitly if multiple versions are installed. - Configure and verify
JAVA_HOMEfor build tools. - Use a real compile-and-run smoke test to confirm the installation is actually usable.

