Jenkins 2.303.1从Java 8升级至Java 11的步骤疑问咨询
Great question! Let me clarify what that official guideline step actually means—it’s not only "install Java 11 and set it as the default JVM", but rather gives you two valid paths to ensure Jenkins uses Java 11, depending on your system’s needs:
Option 1: Set Java 11 as the system-wide default JVM (Recommended if possible)
This is the simplest approach if your entire system doesn’t rely on Java 8 for other applications. Here’s how it works:
- First, install Java 11 using your package manager (e.g.,
apt install openjdk-11-jdkon Debian/Ubuntu,yum install java-11-openjdk-develon RHEL/CentOS). - Then set it as the default JVM using your distro’s alternatives tool:
- For Debian/Ubuntu: Run
sudo update-alternatives --config javaand select the Java 11 entry from the list. Do the same forjavacwithsudo update-alternatives --config javac. - For RHEL/CentOS: Use
sudo alternatives --config javaandsudo alternatives --config javacinstead.
- For Debian/Ubuntu: Run
- Verify the change with
java -versionandjavac -version—both should show Java 11. - Restart Jenkins, and it will automatically pick up the default Java 11.
Option 2: Configure Jenkins to use Java 11 without changing the system default
If you need to keep Java 8 as the system default (e.g., other apps depend on it), you can override the Java version just for Jenkins:
- Locate Jenkins’ startup configuration file: this is usually
/etc/default/jenkins(for systemd setups) or/etc/init.d/jenkins(older init systems). - Open the file and look for lines defining
JAVA_HOMEorJAVA. Update the path to point to your Java 11 installation directory. For example:JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64 - Save the file and restart Jenkins with
sudo systemctl restart jenkins(orsudo service jenkins restartfor older systems). - To confirm Jenkins is using Java 11, go to your Jenkins dashboard → Manage Jenkins → System Information, and check the
java.versionfield.
To sum up the official guideline
The step is saying: Either set Java 11 as the system default (so Jenkins uses it automatically), or if you can’t/won’t change the default, explicitly tell Jenkins to use Java 11 via its startup script. Either way, the end goal is ensuring Jenkins runs on Java 11—you don’t have to do both, just pick the option that fits your system.
内容的提问来源于stack exchange,提问作者Tien Dung Tran

