Complete Guide to Installing JDK 11 on Ubuntu Systems

Nov 10, 2025 · Programming · 12 views · 7.8

Keywords: Ubuntu | JDK 11 | Java Installation | Environment Configuration | OpenJDK

Abstract: This article provides a comprehensive guide to installing OpenJDK 11 on Ubuntu systems, covering multiple installation methods including direct apt installation, PPA repository setup, environment variable configuration, and version verification. Based on high-scoring Stack Overflow answers and official documentation, it offers complete installation workflows and troubleshooting solutions for developers.

Installation Methods Overview

There are two primary recommended approaches for installing JDK 11 on Ubuntu systems: direct installation using the system package manager for OpenJDK 11, or installation through third-party PPA repositories. According to Stack Overflow community best practices, the sudo apt-get install openjdk-11-jdk command is currently the most stable and reliable installation method.

Direct OpenJDK 11 Installation

First, update the system package index to ensure access to the latest software packages:

sudo apt-get update

Then execute the installation command:

sudo apt-get install openjdk-11-jdk

This command installs the complete Java Development Kit, including compilers, debuggers, and other development tools. If you only need to run Java applications without development, install the JRE version instead:

sudo apt-get install openjdk-11-jre

Installation via PPA Repository

If the direct installation method is unavailable, you can install through the official OpenJDK PPA repository:

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt install openjdk-11-jdk

This approach provides more stable version management and update support.

Verification of Installation

After installation completes, verify that the Java environment is properly configured. Check the Java runtime version:

java -version

The expected output should display OpenJDK 11相关信息, such as:

openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

Verify the Java compiler version:

javac -version

This should output information similar to javac 11.0.7.

Environment Variable Configuration

Proper environment variable setup is crucial for Java application execution. Edit the Bash configuration file:

nano ~/.bashrc

Add the following content at the end of the file:

export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH=$PATH:$JAVA_HOME/bin

After saving the file, reload the configuration:

source ~/.bashrc

Verify environment variable settings:

echo $JAVA_HOME
echo $PATH

Testing Java Environment

Create a simple HelloWorld program to test the installation:

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello Java World!");
    }
}

Save as HelloWorld.java and run directly:

java HelloWorld.java

Or compile first then run:

javac HelloWorld.java
java HelloWorld

Both methods should output Hello Java World!.

Troubleshooting

If you encounter Command not found errors, check if the PATH environment variable includes the Java installation directory. For JAVA_HOME is not set errors, properly configure the JAVA_HOME environment variable. Permission issues can be resolved using the sudo command.

Version Management

When multiple Java versions exist on the system, use the following commands to switch default versions:

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

This displays all installed Java versions, allowing users to select the desired default version.

Conclusion

Following the installation methods and configuration steps outlined in this article, users can successfully set up a JDK 11 development environment on Ubuntu systems. The direct installation method is recommended as the primary approach, with PPA repository installation as an alternative when needed. Proper environment variable configuration and version verification are essential for ensuring a functional Java environment.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.