Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
Developer Tools

How to Install Java JDK on Ubuntu (24.04, 22.04 and 26.04)

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For most Ubuntu users, install the distribution’s default Java Development Kit with:

sudo apt update
sudo apt install default-jdk

Then verify both the Java runtime and compiler:

java --version
javac --version

default-jdk is Ubuntu’s release-specific JDK choice, so it does not guarantee the same Java feature release on every Ubuntu version. If a project requires a particular release, install its versioned OpenJDK package instead.

Before you install

Check your Ubuntu release

This guide focuses on supported Ubuntu releases, including Ubuntu 22.04 LTS, 24.04 LTS and 26.04 LTS. Check yours with:

. /etc/os-release
echo "$PRETTY_NAME"

You can also use lsb_release -a. Ubuntu’s supported documentation index is at help.ubuntu.com.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check the CPU architecture

dpkg --print-architecture
uname -m

amd64 normally means 64-bit Intel or AMD hardware; arm64 means 64-bit ARM. Architecture matters particularly when downloading vendor binaries.

JRE versus JDK

A Java Runtime Environment runs Java applications. A Java Development Kit includes the runtime plus development tools such as javac, jar, javadoc, jdb and jconsole. Maven, Gradle, IDEs, Android tooling and Java application builds generally need the JDK. Installing only default-jre can leave javac unavailable. Ubuntu distinguishes these paths in its JRE guide.

Install Ubuntu’s default JDK

  1. Refresh APT’s package indexes:

    sudo apt update

    This refreshes package metadata; it does not upgrade Ubuntu itself.

  2. Install the default JDK:

    sudo apt install default-jdk
  3. Accept the confirmation prompt. APT installs the JDK and registers its commands with Ubuntu’s alternatives system.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Ubuntu documents this as the normal developer installation method at ubuntu.com/developers/docs/howto/java-setup/. The default-jdk package is an alias for the release’s chosen default, not a globally fixed Java version. Ubuntu’s availability table lists OpenJDK 8, 11, 17, 21 and 25 for Ubuntu 24.04 LTS, and those releases plus 26 for Ubuntu 26.04 LTS; package availability varies by release and repository state (availability table).

Verify Java and the compiler

Check both commands:

java --version
javac --version
command -v java
command -v javac

Patch numbers and vendor suffixes can change with Ubuntu updates, so do not expect one exact version string. To inspect the actual executables:

readlink -f "$(command -v java)"
readlink -f "$(command -v javac)"

A working JDK must expose javac as well as java.

Compile a complete test program

mkdir -p ~/java-test
cd ~/java-test

cat > Hello.java <<'EOF'
public class Hello {
    public static void main(String[] args) {
        System.out.println("Java works");
    }
}
EOF

javac Hello.java
java Hello

Expected output:

Java works

Remove the test directory when finished if you wish:

rm -rf ~/java-test

Install a specific Java feature release

Use a versioned package when a project, build tool, Android setup, application server or vendor support matrix requires a particular release:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apt update
sudo apt install openjdk-21-jdk

Other examples are:

sudo apt install openjdk-17-jdk
sudo apt install openjdk-25-jdk

Replace the number with the required feature release. Do not assume that a package available on one Ubuntu release exists on another. Check first:

apt-cache search '^openjdk-[0-9]+-jdk$'
apt policy openjdk-21-jdk

Ubuntu’s Java availability table is the authority for release-specific availability. Ubuntu documentation updated in June 2026 uses OpenJDK 21 as an LTS example, while the later availability table lists OpenJDK 25 in current releases; therefore, choose the version your project requires rather than relying on a universal “latest” label.

Choosing between common packages

Choice Best for Trade-off
default-jdk Most Ubuntu installations The selected feature release differs by Ubuntu release.
openjdk-17-jdk Projects pinned to Java 17 Older than newer releases.
openjdk-21-jdk Projects explicitly requiring Java 21 Not necessarily Ubuntu’s default everywhere.
openjdk-25-jdk Projects targeting Java 25 Unavailable on some older Ubuntu releases.

Manage multiple installed JDKs

List registered JDK installations:

update-java-alternatives --list

To select the default runtime and compiler independently:

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

Select the desired entry from each prompt, then verify both:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
java --version
javac --version

Switching only java can leave the runtime and compiler on different feature releases. Where a complete registered JDK is listed, update-java-alternatives can switch its alternatives together:

sudo update-java-alternatives --set <JDK-name>

Its behavior and syntax are documented in the Ubuntu manpage.

Set JAVA_HOME only when needed

Many modern tools find Java through PATH, so setting JAVA_HOME is not mandatory. Use it when Maven, Gradle, Jenkins, Tomcat, an IDE or a script explicitly requires a JDK directory, or when you want a stable per-project selection.

Find the active JDK directory

dirname "$(dirname "$(readlink -f "$(command -v javac)")")"

Set it for the current shell

export JAVA_HOME="$(dirname "$(dirname "$(readlink -f "$(command -v javac)")")")"
export PATH="$JAVA_HOME/bin:$PATH"

echo "$JAVA_HOME"
"$JAVA_HOME/bin/java" --version
"$JAVA_HOME/bin/javac" --version

Persist it for Bash

cat >> ~/.bashrc <<'EOF'
export JAVA_HOME="$(dirname "$(dirname "$(readlink -f "$(command -v javac)")")")"
export PATH="$JAVA_HOME/bin:$PATH"
EOF

source ~/.bashrc

Graphical applications, IDEs and system services may not read your interactive Bash startup files. Configure those applications or service units separately when necessary. For a system-wide shell setting, use a file under /etc/profile.d/ rather than modifying every user’s shell file.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

If you only need to run Java applications

For runtime-only use, Ubuntu provides:

sudo apt update
sudo apt install default-jre

A version-specific runtime is available with, for example:

sudo apt install openjdk-21-jre

That is sufficient for launching Java programs, but not for compiling source code.

Oracle JDK and other distributions

Oracle JDK

Use Oracle JDK when a vendor or enterprise policy explicitly requires Oracle’s distribution, official Oracle binaries or an Oracle support relationship. Oracle provides Linux .deb packages for Debian-based systems and .tar.gz archives for private or non-root installations. Its packages integrate with Linux alternatives and use paths such as /usr/lib/jvm/jdk-<VERSION>-oracle-<ARCH>. Follow Oracle’s current instructions at docs.oracle.com/en/java/javase/26/install/installation-jdk-linux-platforms.html and obtain downloads from Oracle’s download page. Oracle JDK is not required for ordinary Ubuntu Java development; OpenJDK from APT is simpler to update.

GraalVM Community Edition

GraalVM is a specialized JDK useful for Native Image and other advanced runtime workflows:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo snap install graalvm-jdk
sudo snap install graalvm-jdk --channel=v21

Ubuntu lists GraalVM support for Ubuntu 24.04 LTS and later in its availability documentation. It is unnecessary complexity for normal Java, Maven or Gradle work.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting

“Unable to locate package openjdk-XX-jdk”

Refresh indexes and inspect what your release provides:

sudo apt update
apt-cache policy openjdk-21-jdk
apt-cache search openjdk

The requested release may not be packaged for your Ubuntu version, package indexes may be stale, or a required repository may not be enabled. Use a version listed for your release instead of copying a command from another release.

java works but javac is missing

You likely installed a JRE. Install the default or matching versioned JDK:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo apt install default-jdk
# or
sudo apt install openjdk-21-jdk

The wrong Java version is selected

update-java-alternatives --list
sudo update-alternatives --config java
sudo update-alternatives --config javac
java --version
javac --version

JAVA_HOME points somewhere incorrect

Derive it from the active compiler rather than guessing a directory name:

dirname "$(dirname "$(readlink -f "$(command -v javac)")")"

Export that result as JAVA_HOME, and check that both $JAVA_HOME/bin/java and $JAVA_HOME/bin/javac exist.

A project needs an older release

Install both releases and select the required one with alternatives or in the project’s IDE/build-tool configuration:

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

There is usually no need to uninstall the newer JDK.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You are on an unsupported Ubuntu release

Prefer upgrading to a supported Ubuntu release. If that is not immediately possible, use a JDK package available for the current release or an official vendor .deb or archive when a specific version is genuinely required. Avoid random third-party PPAs as the first fix.

Architecture mismatch

Confirm the machine architecture before downloading a vendor build:

dpkg --print-architecture
uname -m

Oracle publishes separate Linux x64 and Linux aarch64 downloads; they are not interchangeable.

A manually unpacked JDK is not visible to alternatives

Tarballs do not necessarily register java and javac. If your JDK is at a real path such as /opt/jdk-<version>, register both commands:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
sudo update-alternatives --install /usr/bin/java java /opt/jdk-<version>/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /opt/jdk-<version>/bin/javac 1
sudo update-alternatives --config java
sudo update-alternatives --config javac

Manual installations require you to manage updates, PATH, JAVA_HOME and alternatives yourself, so use APT unless you specifically need a portable or non-root installation.

Optional Java development tools

Install an IDE only after the JDK is working. Ubuntu lists these Snap routes:

  • sudo snap install eclipse --classic for Eclipse.
  • sudo snap install intellij-idea-community --classic for IntelliJ IDEA Community Edition.
  • sudo snap install code --classic for Visual Studio Code, followed by Java extensions.
  • sudo snap install android-studio --classic for Android development.

See Ubuntu’s developer setup documentation for its current tool list.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.