How To Install Oracle Java (JDK) On Ubuntu 24.04 LTS, Debian Linux (2024)

3 min read 1 day ago
Published on Nov 13, 2024 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

This tutorial provides a step-by-step guide on how to install Oracle Java Development Kit (JDK) on Ubuntu 24.04 LTS and Debian Linux. Installing the JDK is essential for developers who want to utilize the latest features and performance enhancements of Java. Follow these straightforward instructions to get Java up and running on your system.

Step 1: Download Oracle JDK

  1. Open your web browser and navigate to the Oracle JDK Downloads page.
  2. Locate the section for JDK and select the appropriate package for your system (Linux x64 .deb file).
  3. Accept the Oracle license agreement and download the .deb file to your computer.

Step 2: Open Terminal

  1. Press Ctrl + Alt + T or search for "Terminal" in the Applications menu to open a terminal window.

Step 3: Install Dependencies

  1. Update your package list by running the following command:
    sudo apt update
    

Step 4: Install JDK

  1. Change your directory to where the .deb file is located. For example, if the file is in your Downloads folder, run:
    cd ~/Downloads
    
  2. Install the .deb package using the dpkg command:
    sudo dpkg -i jdk-22_linux-x64_bin.deb
    
  3. If you encounter any dependency issues, resolve them by running:
    sudo apt-get install -f
    

Step 5: Verify the Installation

  1. Check the Java version to ensure the JDK was installed correctly:
    java -version
    
    • You should see output indicating that Java 22 is installed.
  2. Verify the JDK installation path with the following command:
    which java
    

Step 6: Set Up JAVA_HOME Environment Variable

  1. Open your .bashrc file in a text editor:
    nano ~/.bashrc
    
  2. Add the following lines at the end of the file, replacing the path with the actual path where JDK is installed:
    export JAVA_HOME=/usr/lib/jvm/jdk-22
    export PATH=$PATH:$JAVA_HOME/bin
    
  3. Save the file and exit the text editor (in Nano, press Ctrl + X, then Y, and Enter).
  4. Apply the changes by sourcing the .bashrc file:
    source ~/.bashrc
    

Step 7: Verify JAVA_HOME

  1. Confirm that the JAVA_HOME environment variable is set correctly by running:
    echo $JAVA_HOME
    
    • This should output the path to your JDK installation.

Additional Tips

  • Updating JDK: When a new version is released, download and install the new .deb package by following the same steps.
  • Switching Between Java Versions: To manage multiple Java versions, use update-alternatives:
    sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk-22/bin/java 1
    sudo update-alternatives --config java
    

Conclusion

By following these steps, you can successfully install Oracle JDK on your Ubuntu 24.04 LTS or Debian Linux system, enabling you to leverage the latest Java features for your development projects. Remember to keep your JDK updated and manage versions as needed. Happy coding!