Some applications, build pipelines, and vendor support policies still require Java 11 even when newer releases are available. Install Java 11 on Ubuntu with the OpenJDK package so APT handles updates and Java alternatives instead of leaving both to a manual tarball.
OpenJDK 11 comes from Universe on Ubuntu 26.04 LTS (Resolute) and 24.04 LTS (Noble), and from Main on Ubuntu 22.04 LTS (Jammy). Installation is otherwise the same on all three releases. Choose the full JDK for development and builds, a headless JDK for build servers, or a JRE when the system only needs to run Java.
Install OpenJDK 11 on Ubuntu
Ubuntu’s package index lists separate OpenJDK 11 development, runtime, and headless variants. Choose one package that matches the workload instead of installing every variant.
| Package | Includes | Use When |
|---|---|---|
openjdk-11-jdk | Runtime, compiler, debugger, and development tools | Recommended for development, Maven or Gradle builds, and general use |
openjdk-11-jre | Java runtime with desktop libraries | You only need to run Java applications on a desktop system |
openjdk-11-jdk-headless | Compiler and runtime without desktop libraries | Headless build servers and minimal images that still need javac |
openjdk-11-jre-headless | Runtime without desktop libraries | Servers, containers, CI runners, and other non-desktop systems |
Refresh the APT Package Index
Refresh APT’s package list before installing so it can see the latest OpenJDK 11 build in every enabled repository.
sudo apt update
These commands use
sudofor package-management tasks that need root privileges. If your account is not in the sudoers group yet, follow the steps to add a new user to sudoers on Ubuntu before continuing.
Install the OpenJDK 11 Package
Install the full OpenJDK 11 development kit when you need both the runtime and compiler. APT shows the packages and disk-space change before asking you to confirm.
sudo apt install openjdk-11-jdk
If you need only a runtime or headless installation, use the matching package from the table. When unsure, install openjdk-11-jdk; it provides the compiler and development tools as well as the runtime.
Verify OpenJDK 11 on Ubuntu
Check which Java runtime the shell will launch:
java --version
Expect a first line like this. Security updates will change the point release, but the major version should remain 11:
openjdk 11.0.31 2026-04-21
If you installed a JDK package, verify the Java compiler too:
javac --version
javac 11.0.31
Compile and Run a Java 11 Program
This test is for openjdk-11-jdk and openjdk-11-jdk-headless. JRE-only packages do not include javac, so skip it after a runtime-only install. The block uses a unique temporary directory and removes that exact directory when the subshell exits.
(
test_dir="$(mktemp -d "$HOME/openjdk-11-test.XXXXXX")" || exit 1
trap 'rm -r -- "$test_dir"' EXIT
cd "$test_dir" || exit 1
cat > Hello.java <<'EOF'
public class Hello {
public static void main(String[] args) {
System.out.println("OpenJDK 11 compiler and runtime are working.");
}
}
EOF
javac Hello.java
java Hello
)
You should see:
OpenJDK 11 compiler and runtime are working.
Manage Java 11 with Other Java Versions
Ubuntu registers each package-managed JDK as a complete Java profile. If Java 11 sits beside Java 17, 21, or 25, switch the profile rather than changing only java and leaving javac, jar, or other tools on a different branch.
Switch the Complete OpenJDK Profile
List the installed Java profiles and copy the name from the first column:
update-java-alternatives --list
Example output on AMD64:
java-1.11.0-openjdk-amd64 1111 /usr/lib/jvm/java-1.11.0-openjdk-amd64
On Ubuntu 22.04, this command can print a valid profile and still exit with status 1. The printed row is what matters here; copy its first column into the next command.
Profile names end with the system architecture. This AMD64 command selects the complete Java 11 toolset; on another architecture, copy the exact name from --list:
sudo update-java-alternatives --set java-1.11.0-openjdk-amd64
Check the runtime after switching. It should show major version 11:
java --version
If you installed a JDK, check the compiler as well. JRE-only readers should skip this command because runtime packages do not include javac.
javac --version
Find and Verify the JAVA_HOME Path
Many build tools, application servers, and IDEs expect JAVA_HOME to point at the Java directory rather than the java executable. Export the value from the active package-managed command, then check the runtime inside that directory:
export JAVA_HOME="$(dirname "$(dirname "$(readlink -f "$(command -v java)")")")"
printf '%s\n' "$JAVA_HOME"
"$JAVA_HOME/bin/java" --version
If you installed a JDK, check its compiler too. Skip this command after a JRE-only install:
"$JAVA_HOME/bin/javac" --version
The first line prints a path like this on AMD64:
/usr/lib/jvm/java-11-openjdk-amd64
The final suffix can differ by architecture, so use the value printed by the command rather than copying the AMD64 example. This export lasts for the current terminal; make JAVA_HOME persistent only when a project needs it, and follow the instructions to set the Java environment path in Ubuntu without duplicating shell-profile entries.
Compare OpenJDK Versions for Ubuntu
Stay on OpenJDK 11 when an application or vendor explicitly requires it. For new development, choose the newest Java version supported by your framework, dependencies, deployment platform, and vendor.
| Java Version | Best Fit | Ubuntu Guide |
|---|---|---|
| OpenJDK 8 | Legacy applications that explicitly require Java 8 | Install OpenJDK 8 on Ubuntu |
| OpenJDK 11 | Applications and build pipelines pinned to Java 11 | This page |
| OpenJDK 17 | Projects and frameworks with a Java 17 baseline | Install OpenJDK 17 on Ubuntu |
| OpenJDK 21 | Projects tested for Java 21 and its newer language/runtime features | Install OpenJDK 21 on Ubuntu |
| OpenJDK 25 | Projects and frameworks that explicitly support Java 25 | Install OpenJDK 25 on Ubuntu |
Test the application and build pipeline before changing a production JDK. A newer package does not guarantee that the workload supports it.
Update OpenJDK 11 on Ubuntu
APT updates OpenJDK 11 through the same Ubuntu component used for installation. Refresh the package list, then use --only-upgrade with the package you installed. This option prevents APT from installing the named OpenJDK package when it is not already present, although required dependencies can still be updated during the transaction.
sudo apt update
sudo apt install --only-upgrade openjdk-11-jdk
Replace openjdk-11-jdk with the JRE or headless package name if that is what you installed. Every reader can check the runtime after the update:
java --version
After a JDK update, check the compiler too. Both installed tools should still show major version 11:
javac --version
Troubleshoot OpenJDK 11 on Ubuntu
Fix OpenJDK 11 Has No Installation Candidate
If APT cannot locate openjdk-11-jdk or shows Candidate: (none), check the package source before retrying the install:
apt-cache policy openjdk-11-jdk
On Ubuntu 26.04, updated OpenJDK 11 packages come from Universe. The version table should include resolute-updates/universe and resolute-security/universe, although the mirror hostnames can differ:
openjdk-11-jdk:
Installed: (none)
Candidate: 11.0.31+11-1ubuntu1~26.04.2
Version table:
11.0.31+11-1ubuntu1~26.04.2 500
500 http://archive.ubuntu.com/ubuntu resolute-updates/universe amd64 Packages
500 http://security.ubuntu.com/ubuntu resolute-security/universe amd64 Packages
Ubuntu 24.04 also provides OpenJDK 11 through Universe, while Ubuntu 22.04 provides it through Main. Package revisions change with security updates; continue when the Candidate line contains any version.
On Ubuntu 26.04 or 24.04, enable Universe and check again. OpenJDK 11 does not require Multiverse:
sudo apt install software-properties-common
sudo add-apt-repository --yes universe
sudo apt update
apt-cache policy openjdk-11-jdk
Candidate should now contain a version. If it still shows (none) on Ubuntu 26.04 or 24.04, use the Ubuntu Universe and Multiverse guide to check your Ubuntu sources. On Ubuntu 22.04, restore the standard Main source instead of adding Universe for this package.
Fix Java 11 Not Being the Active Version
If java --version shows another branch after OpenJDK 11 is installed, identify every shell match, the resolved binary’s package owner, and any existing JAVA_HOME value before changing packages:
type -a java
java_path="$(readlink -f "$(command -v java)")"
printf '%s\n' "$java_path"
dpkg-query -S "$java_path" 2>/dev/null || printf '%s\n' 'The active Java binary is not owned by a dpkg package.'
printenv JAVA_HOME
java --version
unset java_path
If dpkg-query names an Ubuntu OpenJDK package, list the profiles, copy the Java 11 name from the first column, and set it. This example is for AMD64; use the exact printed name on another architecture:
update-java-alternatives --list
sudo update-java-alternatives --set java-1.11.0-openjdk-amd64
java --version
After a JDK install, retest the compiler too:
javac --version
If dpkg-query names a vendor package instead, use that vendor’s package or selector instructions rather than assuming Ubuntu’s profile command controls it. If the ownership check prints the unowned-binary message, a path under $HOME/.sdkman, $HOME/.asdf, or another prefix may be taking precedence through PATH. Use that manager’s selector or correct the shell profile instead of reinstalling the Ubuntu package.
If the shell output does not explain the mismatch, use the Java version checks for Linux to inspect the build tool, the service user’s PATH, and any stale JAVA_HOME value before changing the system default again.
Fix javac Command Not Found
If java works but javac is missing, you probably installed a JRE instead of a JDK. Confirm that the compiler is absent:
command -v javac || printf '%s\n' 'javac is not installed'
Install the development kit, then retest the compiler:
sudo apt install openjdk-11-jdk
javac --version
javac 11.x confirms that the compiler is ready. If it shows another major version, use the complete-profile fix above and retest.
Remove OpenJDK 11 from Ubuntu
Remove Java 11 only after checking that no application, build, or service still needs it. Use the same package name you installed. This command removes the full JDK package without touching other Java versions:
sudo apt remove openjdk-11-jdk
Removing openjdk-11-jdk may leave its compiler and runtime dependencies installed. If you installed a JRE or headless variant instead, use that package name. Preview autoremove first because it may include unrelated packages you still need:
sudo apt autoremove --dry-run
Run the cleanup only when every package in the dry run belongs to software you no longer need. APT may include unrelated packages that were already marked automatic. Keep the confirmation prompt and cancel if the final list changes.
sudo apt autoremove
Check whether any OpenJDK 11 packages remain installed. Rows beginning with ii are installed; an rc entry in unfiltered dpkg output means the package was removed but left configuration files. If you skipped autoremove to protect unrelated software, Java 11 dependencies may still appear; keeping them is safer than approving the wrong cleanup.
dpkg -l 'openjdk-11-*' 2>/dev/null | grep '^ii' || printf '%s\n' 'No OpenJDK 11 packages are installed.'
Clear Bash’s command cache and check for another Java runtime. If one remains, the block shows its version; otherwise, it prints No Java runtime remains on PATH.
hash -r
if command -v java >/dev/null; then
java --version
else
printf '%s\n' 'No Java runtime remains on PATH.'
fi
Conclusion
OpenJDK 11 now runs from Ubuntu’s APT-managed package, with the compiler available when you chose a JDK. The version checks identify the active Java branch, while the compile test proves the toolchain can build and run a program. Keep APT responsible for security updates, and use update-java-alternatives when another packaged JDK should become the default. For Java builds, a practical next step is to install Apache Maven on Ubuntu.


Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed in published comments:
<code>command</code>command<strong>bold</strong><em>italic</em><a href="https://example.com">link</a><blockquote>quote</blockquote>