Complete Guide to Installing Java Development Kit on Ubuntu Linux

Oct 24, 2025 · Programming · 22 views · 7.8

Keywords: Java Development Kit | Ubuntu Installation | Environment Variables

Abstract: This article provides a comprehensive guide to installing the Java Development Kit (JDK) on Ubuntu Linux systems, focusing on OpenJDK installation methods, environment variable configuration, version management, and common issue resolution. Through step-by-step instructions, it assists developers in quickly setting up a Java development environment, with in-depth analysis of JDK vs. JRE differences, selection strategies for Java distributions, and multi-version Java management techniques.

Overview of Java Development Environment

The Java Development Kit (JDK) is a core component for building and running Java applications, including compilers, debuggers, and other development tools. On Ubuntu Linux systems, installing the JDK typically involves selecting an appropriate Java distribution, configuring environment variables, and verifying the installation. Modern Ubuntu distributions provide OpenJDK by default, which can be installed via simple package management commands.

Installing OpenJDK

OpenJDK is the open-source implementation of Java, functionally similar to Oracle JDK but with a more permissive license. The following steps demonstrate how to install OpenJDK on Ubuntu:

  1. Open Terminal: Launch the terminal via the application menu or using the Ctrl+Alt+T shortcut.

  2. Update Package Index: Execute sudo apt update to ensure the latest package information is retrieved.

  3. Install Default JDK: Run sudo apt install default-jdk to install the Ubuntu-recommended OpenJDK version. This command automatically installs the JDK and its dependent Java Runtime Environment (JRE).

  4. Verify Installation: Use java -version and javac -version to check the versions of the Java runtime and compiler, confirming successful installation.

For specific OpenJDK versions, such as OpenJDK 8, use the command sudo apt install openjdk-8-jdk. Before installation, available versions can be viewed with apt search openjdk.

Configuring Environment Variables

Properly setting environment variables is crucial for the normal operation of Java tools:

Differences Between JDK and JRE

The Java Runtime Environment (JRE) only supports running Java programs, whereas the JDK includes the JRE and development tools. A comparison table is as follows:

<table><tr><th>Feature</th><th>JRE</th><th>JDK</th></tr><tr><td>Runtime Environment</td><td>Yes</td><td>Yes</td></tr><tr><td>Compiler</td><td>No</td><td>Yes</td></tr><tr><td>Debugger</td><td>No</td><td>Yes</td></tr>

When installing the JDK, it is usually unnecessary to install the JRE separately, as the JDK includes a complete runtime.

Managing Multiple Java Versions

Ubuntu supports installing multiple Java versions and switching between them using the update-alternatives tool:

  1. List Available Versions: Execute sudo update-alternatives --config java to view installed Java versions.

  2. Select Default Version: Based on the output, enter the corresponding number to set the system's default Java environment.

  3. Similarly, use sudo update-alternatives --config javac to manage compiler versions.

Common Issues and Solutions

Selecting Java Distributions

OpenJDK and Oracle JDK are the primary choices:

Since Java 11, both have essentially the same functionality, with selection depending on licensing requirements.

Uninstalling Java

To remove a specific JDK version, use the command sudo apt remove openjdk-11-jdk. It is recommended to clean up unused dependencies with apt autoremove.

Conclusion

Installing the JDK on Ubuntu is a straightforward process, with the default-jdk package simplifying installation. Proper configuration of environment variables and management of multiple versions enhance development efficiency. Refer to official documentation and community resources to ensure a stable and compatible 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.