Installing Java walkthrough
1. Check that the required version of Java is installed
java -version
Possible outcomes
Correct version (17.*.*
)
# java -version
openjdk version "17.0.12" 2024-07-16
OpenJDK Runtime Environment (build 17.0.12+7-Ubuntu-1ubuntu220.04)
OpenJDK 64-Bit Server VM (build 17.0.12+7-Ubuntu-1ubuntu220.04, mixed mode, sharing)
Command not found
# java -version
java: command not found
This indicates Java is not installed. To install Java, run the following command:
apt install openjdk-17-jdk
Old version installed
# java -version
openjdk version "11.0.24" 2024-07-16
OpenJDK Runtime Environment (build 11.0.24+8-post-Ubuntu-1ubuntu320.04)
OpenJDK 64-Bit Server VM (build 11.0.24+8-post-Ubuntu-1ubuntu320.04, mixed mode, sharing)
This indicates you are running an older version of Java. To resolve the issue, install Java 17 using the following command:
apt install openjdk-17-jdk
Verify the Java version is now using version 17. If the old version is stil being used, update to the new version by following the prompts of the following command:
update-alternatives --config java
# update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 auto mode
* 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 manual mode
Press <enter> to keep the current choice[*], or type selection number:
Last modified: Thu Aug 29 17:20:27 UTC 2024