How to Install OpenJDK 17 on Ubuntu 24.0.4
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 | openjdk version "17.0.x" 2021-09-14 |
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:
- 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.
- 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:
- Find the installation path of OpenJDK 17 with the following command:This will show the path to the Java executable. It will look something like
1
sudo update-alternatives --config java
/usr/lib/jvm/java-17-openjdk-amd64/bin/java
. - Create or edit the
/etc/environment
file:1
sudo nano /etc/environment
- 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"
- Save the file and close the editor.
- Finally, apply the changes by running:
1
source /etc/environment
- Verify that the
JAVA_HOME
variable is set correctly:This should display the path to your OpenJDK 17 installation.1
echo $JAVA_HOME
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:
- Add the PPA repository:
1
2sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt update - 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.