How To Install Java Jdk On Linux

5 min read

Installing a Java Development Kit (JDK) on Linux is a skill every developer, system administrator, and curious learner should understand. The good news is that Linux offers several reliable ways to install a JDK, from using your distribution’s package manager to downloading an archive manually or using a version manager. Whether you are building Java applications, running build tools like Maven or Gradle, compiling Android projects, or simply preparing your system for development, knowing how to install Java JDK on Linux will save you time and prevent common configuration errors. This guide walks you through the process in a clear, practical way, covering the most popular Linux distributions and helping you configure your environment so Java works correctly from the terminal.

Understanding What a JDK Is and Why You Need It

Before installing anything, it helps to understand what a Java Development Kit (JDK) actually is. Many beginners confuse the JDK with the Java Runtime Environment, or JRE, but they serve different purposes. Now, the JRE is enough to run Java applications, while the JDK includes everything needed to develop and compile Java programs. This includes the Java compiler (javac), the Java Virtual Machine, debugging tools, documentation tools, and many essential development utilities Not complicated — just consistent..

This is the bit that actually matters in practice.

If you plan to write Java code, run build tools, or work with enterprise Java applications, the JDK is required. If you only need to launch a prebuilt Java application, a JRE may be sufficient, but on modern systems the distinction is often less important because many JDK distributions include runtime components anyway Small thing, real impact..

When searching for how to install Java JDK on Linux, you will often see options such as OpenJDK and Oracle JDK. OpenJDK is an open-source implementation of the Java Platform and is usually the default choice for Linux users. It is well maintained, widely compatible, and available in most official software repositories. Oracle JDK is a commercial distribution that can be useful in some enterprise environments, but for most learners and developers, OpenJDK is the simplest and most flexible option Which is the point..

Choosing the Right JDK Version

One of the first decisions you will make is which Java version to install. Consider this: common choices include long-term support releases such as Java 17, Java 21, or older versions like Java 11 depending on your project requirements. If you are starting a new project, it is usually best to choose a recent LTS release unless a framework or organization explicitly requires an older version Most people skip this — try not to..

Here is a simple way to decide:

  • Choose the latest LTS JDK for new projects and modern learning.
  • Choose the version required by your company, course, or framework.
  • Check whether your build tool supports the version before upgrading.
  • Avoid mixing multiple Java versions unless you intentionally need a version switcher.

Once you know which version you need, you can choose one of the installation methods below.

Method 1: Install Java JDK on Debian-Based Systems Like Ubuntu

Debian-based distributions, including Ubuntu, Linux Mint, and Debian itself, use the APT package manager. This is one of the easiest ways to install a JDK because the system handles dependencies, updates, and package management for you.

First, update your package list:

sudo apt update

Then install the JDK. To give you an idea, to install OpenJDK 17, run:

sudo apt install openjdk-17-jdk

To install OpenJDK 21, use:

sudo apt install openjdk-21-jdk

After installation, verify that Java and the compiler are working:

java -version
javac -version

If both commands display version information, the JDK is installed correctly. On Ubuntu, this method is usually the most reliable for beginners because the package is officially maintained and integrated into the system.

Method 2: Install Java JDK on Fedora, RHEL, CentOS, and Rocky Linux

Red Hat-based systems use DNF as their package manager. Fedora, Red Hat Enterprise Linux, CentOS Stream, Rocky Linux, and AlmaLinux all follow this general approach.

To install OpenJDK 17 on Fedora or similar systems, run:

sudo dnf install java-17-openjdk-devel

For OpenJDK 21, use:

sudo dnf install java-21-openjdk-devel

Verify the installation with:

java -version
javac -version

One important detail on Red Hat-based systems is that the -devel package is required for development. The base Java package may provide runtime support, but the development package includes tools such as the compiler That's the whole idea..

Method 3: Install Java JDK on Arch Linux and Manjaro

Arch-based systems use Pacman as their package manager. If you are using Arch Linux, Manjaro, or a related distribution, you can install a JDK directly from the official repositories Worth keeping that in mind..

Update the system package database:

sudo pacman -Syu

Install OpenJDK:

sudo pacman -S openjdk

Arch often provides the latest stable Java version, but if multiple versions are available, you may need to specify the exact package name. After installation, verify it with:

java -version
javac -version

If you have multiple Java versions installed, Arch uses an alternatives system that allows you to choose which version is active That alone is useful..

Method 4: Manual Installation Using a Tarball

Sometimes you need more control than a package manager provides. On top of that, you may want a specific vendor build, a custom installation directory, or multiple JDK versions side by side. In that case, installing the JDK manually from a compressed archive is a useful approach.

People argue about this. Here's where I land on it.

Download the appropriate JDK archive, then extract it into a location such as /opt or /usr/lib/jvm Simple, but easy to overlook. Turns out it matters..

For example:

sudo mkdir -p /usr/lib/jvm
sudo tar -xzf jdk-version.tar.gz -C /usr/lib/jvm

After extraction, set up environment variables so the system knows where to find Java. This is also the point where you will often configure JAVA_HOME.

Manual installation gives you flexibility, but it requires more maintenance. Package managers are usually better for routine use because

Just Went Online

Dropped Recently

Close to Home

Based on What You Read

Thank you for reading about How To Install Java Jdk On Linux. We hope the information has been useful. Feel free to contact us if you have any questions. See you next time — don't forget to bookmark!
⌂ Back to Home