This guide walks you through the step-by-step process, ensuring you get OpenJDK 17 up and running on your system in no time.

Step 1: Update Package Lists

Before starting the installation process, it’s always a good practice to update your system’s package list. This ensures that you’re installing the latest version available in the repositories.

Open your terminal and run the following command:

1
sudo apt update

This command will refresh the list of available packages and their versions, making sure you are working with the most recent versions of software.

Step 2: Install OpenJDK 17

Ubuntu 24.0.4 includes OpenJDK 17 in its official package repositories, so you can easily install it using the apt package manager.

To install OpenJDK 17, execute the following command:

1
sudo apt install openjdk-17-jdk

This will install the OpenJDK 17 Development Kit (JDK), which includes the Java Runtime Environment (JRE) as well as development tools like the compiler and debugger.

Step 3: Verify the Installation

After the installation is complete, you can verify that OpenJDK 17 is installed correctly by checking the version with the following command:

1
java -version

You should see an output similar to this:

1
2
3
openjdk version "17.0.x" 2021-09-14
OpenJDK Runtime Environment (build 17.0.x+xx-xxx)
OpenJDK 64-Bit Server VM (build 17.0.x+xx-xxx, mixed mode, sharing)

This confirms that OpenJDK 17 is installed and running on your system.

Step 4: Set the Default Java Version (Optional)

If you have multiple versions of Java installed on your system, you may want to set OpenJDK 17 as the default Java version. To do this, you can use the update-alternatives command:

  1. First, configure the java alternatives:
1
sudo update-alternatives --config java

This will present a list of installed Java versions. You can choose the one corresponding to OpenJDK 17 by entering the number next to it.

  1. You can also set the default javac (Java compiler) version in a similar manner:
1
sudo update-alternatives --config javac

Step 5: Set JAVA_HOME (Optional)

Many Java applications require the JAVA_HOME environment variable to be set. To set it for OpenJDK 17, follow these steps:

  1. Find the installation path of OpenJDK 17 with the following command:
    1
    sudo update-alternatives --config java
    This will show the path to the Java executable. It will look something like /usr/lib/jvm/java-17-openjdk-amd64/bin/java.
  2. Create or edit the /etc/environment file:
    1
    sudo nano /etc/environment
  3. Add the following line at the end of the file, adjusting the path based on your system’s installation path:
    1
    JAVA_HOME="/usr/lib/jvm/java-17-openjdk-amd64"
  4. Save the file and close the editor.
  5. Finally, apply the changes by running:
    1
    source /etc/environment
  6. Verify that the JAVA_HOME variable is set correctly:
    1
    echo $JAVA_HOME
    This should display the path to your OpenJDK 17 installation.

Step 6: Optional - Install OpenJDK 17 from a PPA (if not available in repositories)

If, for any reason, OpenJDK 17 is not available in your Ubuntu 24.0.4 repositories, you can use the openjdk PPA (Personal Package Archive). Here’s how:

  1. Add the PPA repository:
    1
    2
    sudo add-apt-repository ppa:openjdk-r/ppa
    sudo apt update
  2. Then install OpenJDK 17:
    1
    sudo apt install openjdk-17-jdk

Conclusion

You’ve successfully installed OpenJDK 17 on Ubuntu 24.0.4. Whether you’re a developer setting up a Java environment or a server administrator configuring a Java-based application, these steps should have you up and running in no time.

If you need further help or have any issues, don’t hesitate to check the official OpenJDK documentation or ask for support in relevant online forums.