How to Install Oracle JDK on Ubuntu 24.04
You install Oracle JDK on Ubuntu 24.04 by manually downloading the tarball and extracting it to your system.
Oracle JDK is Oracle’s official Java Development Kit, offering a complete set of tools for developing and running Java applications, including the JRE, compiler, and debugger.
This guide focuses on installing Oracle JDK 21, the current Long-Term Support (LTS) release, known for its enhanced performance.
You will need administrator privileges to successfully complete this installation process.
Install Oracle JDK by downloading the .deb package and running `sudo apt install ./jdk-XX_linux-x64_bin.deb`. Then, configure your environment by sourcing `/etc/profile.d/java.sh`. Verify the installation with `java –version`.
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.
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
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.
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.
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.
java --version
It should output similar lines shown below.
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.
sudo update-alternatives --config java
Select the Java version you wish to use as the default.
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.
sudo update-alternatives --config javac
Choose the javac version you want to set as default.
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 --versioncommand verifies that Oracle JDK is running correctly. - The
update-alternativescommand 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.
Can we install Oracle on Ubuntu?
As for Linux distributions, Oracle recommends to install Oracle database on Red-Hat, Oracle Linux, and SUSE Linux Enterprise Server. However, you can install Oracle on Ubuntu Linux and Open SUSE Linux as well.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips 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.
No comments yet — be the first to share your thoughts!