Install Oracle Java SE on Oracle Linux


Oracle’s Java Platform, Standard Edition (Java SE) lets you develop and deploy Java applications on desktops and servers.

The Java Platform Standard Edition Development Kit (JDK) includes tools for developing, testing, and monitoring programs written in the Java programming language and running on the Java platform. The JDK offers developers and users a rich user interface and the performance, versatility, portability, and security that today’s applications require.

Beyond these great features, Oracle provides the Oracle JDK free for commercial and production use. When you combine Oracle Java with Oracle’s highly performant, reliable, and cloud-ready operating system, Oracle Linux, you get an ideal environment with out-of-the-box optimizations for Oracle software, excellent for running Oracle Java.


In this lab, you’ll learn how to:


Verify the Lab Environment

Note: When using the free lab environment, see Oracle Linux Lab Basics for connection and other usage instructions.

  1. Open a terminal and connect via ssh to the ol-node01 instance.

    ssh oracle@<ip_address_of_ol_node01>
  2. Check the availability of the Oracle Java packages.

    sudo dnf list jdk*

    When using Oracle Linux in Oracle Cloud Infrastructure (OCI), the Oracle Java packages exist in the ol<version>_oci_included repositories. OCI installs and enables these repositories by default when provisioning an Oracle Linux instance.

    Note: Oracle splits the JDK installation on Oracle Linux into two packages: jdk-<version>-headless and jdk-<version>-headful.

    • jdk-<version>-headless is a headless Java Runtime for running non-GUI applications.
    • jdk-<version>-headful is headful Java Runtime and a set of Development Tools for developing and running all types of applications. The jdk-<version>-headful package requires the jdk-<version>-headless package. When installing these packages together, they provide the same functionality as the JDK package Oracle provides for Generic Linux Platforms. See the Installation Guide in the Oracle JDK documentation for more details.

Install Oracle Java

  1. Install one of the Oracle Java versions.

    sudo dnf install -y jdk-21-headful
  2. Confirm the installation by checking the JDK version.

    java -version

    Note: To help ensure that your systems are secure when using Java-based content, Oracle strongly recommends that all Java SE users upgrade to the latest release available for the version you are using.

(Optional) Setting the default JDK on a system with multiple versions

If multiple versions of the JDK exist on an Oracle Linux system, users can set the default version using the alternatives command, which maintains symbolic links determining default commands. See the update-alternatives(8) manual page for more details.

  1. Install Oracle Java 17.

    sudo dnf install -y jdk-17-headful
  2. Confirm Oracle Java 21 is the default version.

    java -version
  3. Change the default to Oracle Java 17.

    sudo alternatives --config java

    Type 2 and the ENTER key to select Oracle Java 17.

  4. Recheck the version.

    java -version

    Notice the output now shows the version for Oracle Java 17.

  5. Switch the default back to Oracle Java 21.

    sudo alternatives --config java

    Type 1 and the ENTER key to select Oracle Java 21.

Write, Compile and Run a Java Program

A “Hello, World!” program outputs Hello, World! or a similar welcome message on the screen. The syntax creates a straightforward program and is commonly used to introduce a new programming language to new developers.

  1. Create the Java program.

    tee ~/ > /dev/null <<'EOF'
    class HelloWorld {
      public static void main(String[] args) {
        System.out.println("Hello, World!"); 
  2. Compile the Java program.

  3. Run the Java program.

    java HelloWorld


That completes the lab and demonstrates how to install the Oracle Java SE Platform on Oracle Linux and write your first program.

For more information

More Learning Resources

Explore other labs on or access more free learning content on the Oracle Learning YouTube channel. Additionally, visit to become an Oracle Learning Explorer.

For product documentation, visit Oracle Help Center.