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 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 --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.
Leave a Reply Cancel reply