How to Install Oracle JDK on Ubuntu 24.04
Installing Oracle JDK on Ubuntu 24.04 involves downloading a specific file from Oracle’s website and setting it up on your computer.
Oracle JDK is Oracle’s official toolkit for building and running Java programs. It includes everything you need, like the Java Runtime Environment (JRE) and tools to compile code.
This guide focuses on installing Oracle JDK 21, which is the latest version with long-term support and improved performance.
You’ll need administrator rights on your Ubuntu machine to follow these steps.
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
To install Oracle JDK on Ubuntu 24.04, you need to download the Java SE Development Kit from Oracle’s official site. After getting the correct file, you will use a few commands in your computer’s terminal to finish the setup. Remember to write down the exact version number of the JDK you download.
Download the latest Java SE Development Kit 23 release.
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
After installing Oracle JDK on Ubuntu, you can easily check if it’s working by opening your terminal. Type the command `java –version` and press Enter. If the installation was successful, you’ll see details about the Java version, confirming it’s ready to use.
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 more than one Java version on your Ubuntu system, you can pick which one to use as the main default. Just open your terminal and run the command `sudo update-alternatives –config java`. This shows a list of all your installed Java versions, letting you choose the one you want.
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:
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!