Jenkins: invalid Java version: openjdk version “18.0.2”
August 15, 2023 2023-08-18 4:56Jenkins: invalid Java version: openjdk version “18.0.2”
While I’m trying to installing the Jenkins software in Ubuntu 22.04 LTS version, the Jenkins couldn’t start getting the service even tried two or three times and through error look like below,
After analysed the above errors, seems to be something the Java version is mismatched which installed in the Ubuntu machine. So tried to find out what java version can be support for this Jenkins server. Just I opened the service start-up file and find the supportable Java version in /etc/init.d/jenkins.
vim /etc/init.d/jenkins
See the screenshot below, can support either Java 17 or Java 11.
Then I checked the java package installed in Ubuntu machine and can see the version Java 18 using the command below,
java -version
openjdk version “18.0.2-ea” 2022-07-19
OpenJDK Runtime Environment (build 18.0.2-ea+9-Ubuntu-222.04)
OpenJDK 64-Bit Server VM (build 18.0.2-ea+9-Ubuntu-222.04, mixed mode, sharing)
Just list out the installed the Java packages using the command below and change the default version,
update-java-alternatives --list
java-1.11.0-openjdk-amd64 1111 /usr/lib/jvm/java-1.11.0-openjdk-amd64
java-1.18.0-openjdk-amd64 1811 /usr/lib/jvm/java-1.18.0-openjdk-amd64
Then, changed the version from 18 to 11 using the command below,
sudo update-alternatives --config java
Now, checked the Java which has configured the default version,
java -version
openjdk version “11.0.20” 2023-07-18
OpenJDK Runtime Environment (build 11.0.20+8-post-Ubuntu-1ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.20+8-post-Ubuntu-1ubuntu122.04, mixed mode, sharing)
Now, able to start the Jenkins service using the command below,
service jenkins start
or
systemctl start jenkins.service