Skip to content
Ubuntu Linux

How to Install Oracle JDK on Ubuntu 24.04

Richard
Written by
Richard
Updated 5 min read
How to Install Oracle JDK on Ubuntu 24.04
How to Install Oracle JDK on Ubuntu 24.04

Installing Oracle JDK on Ubuntu 24.04 gives you the official toolkit for building and running Java programs. Oracle JDK includes the Java Runtime Environment (the part that runs Java apps) and the tools you need to write and compile code, such as the javac compiler.

The examples below were written with Oracle JDK 23. The steps are the same for JDK 21, the long-term support (LTS) release, or for any newer version. You only need to change the version number in the commands. You need an Ubuntu machine and an account with administrator (sudo) rights to complete these steps.

⚡ Quick Answer

Download the x64 Debian Package from Oracle’s Java SE Development Kit 23 page, then run sudo apt install./jdk-23_linux-x64_bin.deb in the folder holding the file. Use the Arm64 package on ARM machines. Afterwards, add JAVA_HOME and PATH to /etc/profile.d/java.sh, open a new terminal, and run java –version to confirm the JDK is installed.

Advertisement

Install Oracle JDK

The installation has three parts. First you download the Java SE Development Kit package from the Oracle website. Then you install it with a few terminal commands. Finally you set up the environment variables so Ubuntu can find it. Write down the exact version number of the file you download. You will need it later, because the file names and paths in the commands include it.

  1. Open the Oracle Java downloads page and download the latest  Java SE Development Kit 23 release.
  2. Choose the Linux tab and pick the file that matches your system. For Ubuntu, that is the x64 Debian Package on a standard 64-bit PC, or the Arm64 version on an ARM machine. Oracle also offers a compressed archive (tar.gz), which is the other route covered below.
  3. Save the file somewhere easy to find, such as your Downloads folder.
📝Good to KnowCheck the version number in the file name you downloaded and keep it handy. If Oracle lists a newer version than 23 when you read this, download that one instead and use its number wherever the commands below show a version.
Advertisement

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

  1. Open a terminal in the folder where you saved the file. Right-click inside the folder in Files and choose Open in Terminal, or use cd to move there.
  2. Run the commands from the block below, replacing the version number if yours is different. Enter your password when sudo asks for it. Nothing shows on screen as you type it, which is normal.
  3. Wait for the command to finish and return you to the prompt. If it reports a file not found error, the version number or folder is usually wrong.
⬛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"

If you downloaded the archive package instead of the DEB file, run the commands below to install Oracle Java. Make sure you picked the archive that matches your system’s architecture (x64 or Arm64). Run them from the folder that contains the downloaded file.

Again, the current latest version is jdk-23. If you downloaded a different version, change the number in the commands to match your file.

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

After installing the packages, configure Ubuntu so Oracle JDK works properly. The command below sets the JAVA_HOME variable and adds Java to the environment PATH.

  1. In the same terminal, run the command from the block below.
  2. If the command writes a configuration script, it should finish without errors. If it complains about permissions, run it with sudo.
🐧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

Now activate the script so the new settings load. Run the command below. It applies to the terminal you are working in right now.

📝Good to KnowTerminals you opened earlier will not pick up the change. If Java is not found later, close the terminal and open a new one, or log out and back in.
🐧Bash / Shell
sudo -s
source /etc/profile.d/java.sh

Test Oracle JDK

To confirm the installation worked, run a quick version check.

  1. Open a terminal.
  2. Type java –version and press Enter.
  3. Read the output. It should show the Java version and build details of the JDK you installed.

If you see “command not found”, the PATH settings were not loaded. Open a fresh terminal or log out and back in, then try again. If it shows a different Java version than you expected, another Java is set as the default. The last section of this guide shows how to change that.

💻Code
java --version

The output should look similar to the lines shown below. Your version number and build date will differ if you installed a different release.

💻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 more than one Java release installed, for example OpenJDK from the Ubuntu repositories alongside Oracle JDK, you can choose which one is the default with the update-alternatives tool. It shows a numbered list of every Java build on the system and lets you pick one.

Advertisement
  1. Run the command from the block below in your terminal.
  2. Look at the numbered list that appears. The entry marked with an asterisk (*) is the current default.
🐧Bash / Shell
sudo update-alternatives --config java

Select the Java version you want as the default.

  1. Type the number next to the Java version you want.
  2. Press Enter. The tool confirms the change and the asterisk moves to your choice.

If you press Enter without typing a number, the current selection stays as it is.

💻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:

The compiler is set separately from the runtime. Also run the command below to choose the default javac version. Without this step, you can end up running one Java version and compiling with another.

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

Choose the javac version you want to set as the default.

  1. Type the number of the javac entry that matches the Java version you chose above.
  2. Press Enter.
  3. Run java –version again to check the result. You can run these commands again at any time to switch back.
💻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 gives developers a solid, high-performance environment for Java application development.
  • Following the steps above gives you a proper setup, including the Java Home and Path configurations.
  • Testing the installation with the java --version command confirms that Oracle JDK is running correctly.
  • The update-alternatives command makes it easy to manage multiple JDK installations and select the version you want.
  • With Oracle JDK installed and configured, you can start developing Java applications.

Have a question about this guide?

Answered by AI from this guide. Good questions may be added to this page — please don't include personal details.

Did this guide fix your problem?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

No comments yet — be the first to share your thoughts!

Leave a Comment

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