Ubuntu Linux

How to Install Oracle JDK on Ubuntu 24.04

Richard
Written by
Richard
Mar 11, 2025 Updated Mar 20, 2026 4 min read

This article explains how to install Oracle JDK on Ubuntu 24.04.

Oracle JDK (Java Development Kit) is a software development kit provided by Oracle Corporation for developing and running Java applications. It includes tools necessary for Java development, such as the Java Runtime Environment (JRE), compilers, and debuggers.

Oracle JDK is not just a good choice, but a reliable and high-performance choice for developers and businesses looking to build and run Java applications.

Our previous post showed you how to install the open-source (OpenJDK) on Ubuntu. You can read it from the link below.

Install OpenJDK on Ubuntu

Install Oracle JDK

If you want to use the Oracle JDK version, please follow the steps below.

Download the latest  Java SE Development Kit 23 release.

Note the version number you are downloading. If a newer version number is available, choose that one instead.

You can install the Java DEB package by executing the commands below. As of this writing, the latest version of the Java JDK is 23.

Command Prompt
cd /tmp
wget --no-check-certificate -c --header "Cookie: oraclelicense=accept-securebackup-cookie" "https://download.oracle.com/java/23/latest/jdk-23_linux-x64_bin.deb"

Once you have downloaded the correct archive package for your system, run the commands below to install Oracle Java.

Again, the current latest version is jdk-23

🐧Bash / Shell
sudo apt install ./jdk-23_linux-x64_bin.deb

After installing all the packages, run the command below to configure Ubuntu so that Oracle JDK can function properly, including setting the JAVA_HOME variable and the environment PATH.

🐧Bash / Shell
sudo tee -a /etc/profile.d/java.sh <<'EOF'
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac))))
export PATH=$PATH:$JAVA_HOME/bin
EOF

Activate the script by running the command below.

🐧Bash / Shell
sudo -s
source /etc/profile.d/java.sh

Test Oracle JDK

Now that Oracle JDK is installed and configured, you can validate and test to see if everything works by running the command below.

💻Code
java --version

It should output similar lines shown below.

💻Code
java 23.0.2 2025-01-21
Java(TM) SE Runtime Environment (build 23.0.2+7-58)
Java HotSpot(TM) 64-Bit Server VM (build 23.0.2+7-58, mixed mode, sharing)

Oracle JDK is installed and ready to use.

Choose the default

If you have multiple versions of Oracle JDK installed, you can use the [update-alternatives] command to switch and set the default version to use.

🐧Bash / Shell
sudo update-alternatives --config java

Select the Java version you wish to use as the default.

💻Code
  Selection    Path                                         Priority   Status
------------------------------------------------------------
* 0 /usr/lib/jvm/jdk-23.0.2-oracle-x64/bin/java 385892352 auto mode
1 /usr/lib/jvm/jdk-23.0.2-oracle-x64/bin/java 385892352 manual mode

Press <enter> to keep the current choice[*], or type selection number:

Also run the command below to choose the default javac version.

🐧Bash / Shell
sudo update-alternatives --config javac

Choose the javac version you want to set as default.

💻Code
  Selection    Path                                          Priority   Status
------------------------------------------------------------
* 0 /usr/lib/jvm/jdk-23.0.2-oracle-x64/bin/javac 385892352 auto mode
1 /usr/lib/jvm/jdk-23.0.2-oracle-x64/bin/javac 385892352 manual mode

Press <enter> to keep the current choice[*], or type selection number:

That should do it!

Conclusion:

  • Installing Oracle JDK on Ubuntu allows developers to leverage a robust and high-performance environment for Java application development.
  • Following the outlined steps ensures a proper setup, including the Java Home and Path configurations.
  • Testing the installation with the java --version command verifies that Oracle JDK is running correctly.
  • The update-alternatives command simplifies managing multiple JDK installations, allowing easy selection of the desired version.
  • With Oracle JDK successfully installed and configured, you can start developing Java applications efficiently.

Frequently Asked Questions

How do I install Oracle JDK on Ubuntu 24.04?

To install Oracle JDK on Ubuntu 24.04, download the latest Java SE Development Kit DEB package from the Oracle website. Then, use the command 'sudo apt install ./jdk-23_linux-x64_bin.deb' to install it.

What is the difference between Oracle JDK and OpenJDK?

Oracle JDK is a commercial version of the Java Development Kit provided by Oracle Corporation, while OpenJDK is the open-source implementation of the Java Platform. Oracle JDK includes additional features and support that may be beneficial for enterprise applications.

How can I set the JAVA_HOME variable on Ubuntu?

To set the JAVA_HOME variable on Ubuntu, you can create a script in '/etc/profile.d/java.sh' that exports JAVA_HOME with the path to your JDK installation. Use the command 'export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac))))' to set it correctly.

How do I check if Oracle JDK is installed correctly?

You can check if Oracle JDK is installed correctly by running the command 'java --version' in the terminal. If installed properly, it should display the version of Java along with the build information.

What should I do if I have multiple versions of Oracle JDK installed?

If you have multiple versions of Oracle JDK installed, you can use the 'update-alternatives' command to select the default version. Run 'sudo update-alternatives --config java' and follow the prompts to choose your preferred version.

Was this guide helpful?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, the owner and lead writer at Geek Rewind, is a tech enthusiast passionate about simplifying complex IT topics. His years of hands-on experience in system administration and enterprise IT operations have honed his ability to provide practical insights and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

Leave a Reply

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

Exit mobile version