jenkins升级jdk版本到21
问题

参考链接如下
https://www.jenkins.io/doc/book/platform-information/support-policy-java/
解决
根据对应关系,当前使用的jenkins版本是Jenkins 2.528.3
这里我们直接升级到openjdk21即可。
注意:官方升级建议先打个快照,或者备份jenkins家目录,默认位置是 /usr/lib/jenkins,以免出现问题导致无法恢复。
所有jdk汇总下载地址
openjdk21直链下载地址
安装新版本
[root@test src]# update-alternatives --install /usr/bin/java java /usr/local/src/jdk-21.0.2/bin/java 300
使用新版本openjdk21
[root@test src]# update-alternatives --install /usr/bin/java java /usr/local/src/jdk-21.0.2/bin/java 300
[root@test src]# update-alternatives --config java
共有 4 个提供“java”的程序。
选项 命令
-----------------------------------------------
1 java-11-openjdk.x86_64 (/usr/lib/jvm/java-11-openjdk-11.0.23.0.9-2.el7_9.x86_64/bin/java)
* 2 /usr/local/src/jdk-17/bin/java
+ 3 /usr/local/src/jdk-25.0.1/bin/java
4 /usr/local/src/jdk-21.0.2/bin/java
按 Enter 保留当前选项[+],或者键入选项编号:4
重启jenkins生效
systemctl stop jenkins
systemctl start jenkins
验证
升级完成之后,可以验证一下jenkins对应使用的java版本
http://192.168.1.100:8080/manage/systemInfo
java.version 21.0.2
升级完成✅
踩坑部分
当时直接使用了25版本,会导致这个版本jenkins无法启动,恢复21版本之后正常。
[root@test ~]# systemctl start jenkins
Job for jenkins.service failed because the control process exited with error code. See "systemctl status jenkins.service" and "journalctl -xe" for details.
[root@test ~]# journalctl -xe
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit jenkins.service has begun starting up.
1月 07 13:37:23 test jenkins[494879]: Running with Java 25 from /usr/local/src/jdk-25.0.1, which is not yet fully supported.
1月 07 13:37:23 test jenkins[494879]: Run the command again with the --enable-future-java flag to enable preview support for future Java versions.
1月 07 13:37:23 test jenkins[494879]: Supported Java versions are: [17, 21]
1月 07 13:37:23 test jenkins[494879]: See https://jenkins.io/redirect/java-support/ for more information.
1月 07 13:37:23 test systemd[1]: jenkins.service: main process exited, code=exited, status=1/FAILURE
1月 07 13:37:23 test systemd[1]: Failed to start Jenkins Continuous Integration Server.
-- Subject: Unit jenkins.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit jenkins.service has failed.
--
-- The result is failed.
1月 07 13:37:23 test systemd[1]: Unit jenkins.service entered failed state.
1月 07 13:37:23 test systemd[1]: jenkins.service failed.
1月 07 13:37:23 test systemd[1]: jenkins.service holdoff time over, scheduling restart.
1月 07 13:37:23 test systemd[1]: Stopped Jenkins Continuous Integration Server.
-- Subject: Unit jenkins.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit jenkins.service has finished shutting down.
1月 07 13:37:23 test systemd[1]: Starting Jenkins Continuous Integration Server...
-- Subject: Unit jenkins.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit jenkins.service has begun starting up.
1月 07 13:37:24 test jenkins[494944]: Running with Java 25 from /usr/local/src/jdk-25.0.1, which is not yet fully supported.
1月 07 13:37:24 test jenkins[494944]: Run the command again with the --enable-future-java flag to enable preview support for future Java versions.
1月 07 13:37:24 test jenkins[494944]: Supported Java versions are: [17, 21]
1月 07 13:37:24 test jenkins[494944]: See https://jenkins.io/redirect/java-support/ for more information.
1月 07 13:37:24 test systemd[1]: jenkins.service: main process exited, code=exited, status=1/FAILURE
1月 07 13:37:24 test systemd[1]: Failed to start Jenkins Continuous Integration Server.
-- Subject: Unit jenkins.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit jenkins.service has failed.
--
-- The result is failed.
1月 07 13:37:24 test systemd[1]: Unit jenkins.service entered failed state.
1月 07 13:37:24 test systemd[1]: jenkins.service failed.
1月 07 13:37:24 test systemd[1]: jenkins.service holdoff time over, scheduling restart.
1月 07 13:37:24 test systemd[1]: Stopped Jenkins Continuous Integration Server.
-- Subject: Unit jenkins.service has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit jenkins.service has finished shutting down.
1月 07 13:37:24 test systemd[1]: start request repeated too quickly for jenkins.service
1月 07 13:37:24 test systemd[1]: Failed to start Jenkins Continuous Integration Server.
-- Subject: Unit jenkins.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit jenkins.service has failed.
--
-- The result is failed.
1月 07 13:37:24 test systemd[1]: Unit jenkins.service entered failed state.
1月 07 13:37:24 test systemd[1]: jenkins.service failed.
关注我们,获取更多DevOps和安全更新资讯!
本文作者:运维技术团队:辣个男人Devin
发布日期:2026年01月07日
适用系统:Linux