How to Install Java on Linux: Methods, Versions, and What to Know First

Java remains one of the most widely used programming platforms in the world — powering everything from Android apps and enterprise software to development tools and web servers. On Linux, installing Java is straightforward once you understand the landscape, but there are enough variables — distribution, Java version, JDK vs JRE, package manager — that the "right" approach genuinely depends on your setup.

JDK vs JRE: What You're Actually Installing

Before running any commands, it helps to know what you're installing.

  • JRE (Java Runtime Environment): Lets you run Java applications. If you're using software that requires Java — like a Minecraft server or a business application — this is often enough.
  • JDK (Java Development Kit): Includes the JRE plus compilers and tools for writing and building Java programs. Developers need this.

Many modern guides recommend installing the JDK even for general use, since it includes everything in the JRE and avoids issues where certain applications expect developer tools to be present.

OpenJDK vs Oracle JDK

There are two major Java distributions you'll encounter on Linux:

DistributionLicenseBest For
OpenJDKGPL open sourceGeneral use, most Linux distros
Oracle JDKCommercial/free for personal useEnterprise environments with Oracle support

OpenJDK is the default choice for most Linux users. It's open source, actively maintained, and available directly through standard package managers on virtually every major distribution. Oracle JDK requires a separate download from Oracle's website and has licensing terms that matter for commercial deployments.

For most developers and general users, OpenJDK is the practical starting point.

Java Versions: Which One Matters

Java has version numbers that affect compatibility. The most important distinction:

  • LTS versions (Long-Term Support): Java 8, 11, 17, and 21 are LTS releases. These receive security and maintenance updates for years and are the versions most production software targets.
  • Non-LTS versions: Released between LTS cycles, these are useful for testing new features but not ideal for stable environments.

Java 17 and Java 21 are the current LTS versions most commonly recommended for new projects. Java 11 still sees wide use in enterprise environments. Java 8, while aging, remains present in legacy systems. 🔢

Installing Java on Ubuntu and Debian-Based Distros

Ubuntu and Debian use apt as their package manager. Installing OpenJDK is a few commands:

sudo apt update sudo apt install default-jdk 

This installs the default JDK version recommended for your Ubuntu release. To install a specific version:

sudo apt install openjdk-17-jdk sudo apt install openjdk-21-jdk 

After installation, confirm it worked:

java -version javac -version 

If you only need the JRE:

sudo apt install default-jre 

Installing Java on Fedora, RHEL, and CentOS

Red Hat-based distributions use dnf (or yum on older systems):

sudo dnf install java-17-openjdk-devel 

Replace 17 with 11 or 21 depending on your target version. The -devel suffix installs the full JDK; omitting it installs only the JRE equivalent.

Verify the install:

java -version 

Installing Java on Arch Linux

Arch uses pacman:

sudo pacman -S jdk-openjdk 

For a specific version, search the Arch repositories or AUR:

sudo pacman -S jdk17-openjdk 

Managing Multiple Java Versions 🔄

Running multiple Java versions simultaneously is common for developers who maintain projects with different requirements. Linux handles this through version management tools.

update-alternatives (Debian/Ubuntu):

sudo update-alternatives --config java 

This presents a menu listing all installed Java versions and lets you select the active default.

alternatives (Fedora/RHEL):

sudo alternatives --config java 

SDKMAN is a popular third-party tool that works across distributions and lets you install and switch between Java versions with minimal friction:

sdk install java 17.0.x-open sdk use java 17.0.x-open 

SDKMAN is particularly useful when working across multiple projects with different Java version requirements.

Setting JAVA_HOME

Many Java-dependent tools and build systems (Maven, Gradle, etc.) look for a JAVA_HOME environment variable. After installing Java, you can set this in your shell configuration file (~/.bashrc, ~/.zshrc, etc.):

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

Run source ~/.bashrc (or equivalent) to apply changes to the current session.

Variables That Affect Your Best Approach

Installation itself is mechanical, but the version and method that make sense for you depends on several factors:

  • Linux distribution and version: Package availability varies. Ubuntu LTS repositories don't always carry the latest Java versions by default.
  • What you're running: A Minecraft server has different Java version requirements than a Spring Boot application or an Android build environment.
  • Single vs. multiple projects: If you work across projects with different Java requirements, a version manager like SDKMAN is worth the extra setup.
  • Personal vs. commercial use: Oracle JDK's licensing terms change depending on how you're using it.
  • System architecture: Most modern Linux systems are x86_64, but ARM-based machines (Raspberry Pi, Apple Silicon via VMs, etc.) require architecture-specific builds.

The installation steps are consistent across setups — the meaningful differences lie in which version you need and how many you need to manage at once. Those answers sit with your specific environment and the software you're working with. 🐧