How to Change Java JRE Version for Jenkins Server on Linux (JDK 1.7 to 1.8 Migration Guide)


2 views

When running Jenkins on Linux, the Java runtime environment (JRE) version is crucial for plugin compatibility. Many modern Jenkins plugins require Java 8 or higher, while older installations might still run on Java 7. The challenge occurs when you have multiple Java versions installed but Jenkins persists in using an older version.

First, verify which Java version Jenkins is currently using:

ps aux | grep jenkins
# Look for -Djava.home or JAVA_HOME in the output

# Alternatively check system configuration:
cat /etc/default/jenkins | grep JAVA

For Debian/Ubuntu systems with Jenkins installed via package manager:

# Edit the init configuration
sudo nano /etc/default/jenkins

# Modify these parameters:
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
JAVA_ARGS="-Djava.awt.headless=true -Xmx2048m"

If running Jenkins via the WAR file with a servlet container:

# Set environment variables before startup
export JAVA_HOME=/path/to/java8
export PATH=$JAVA_HOME/bin:$PATH

# Then start Jenkins with:
java -jar jenkins.war --httpPort=8080

For modern Linux systems using systemd:

# Edit the service unit file
sudo systemctl edit --full jenkins

# Add these directives under [Service]:
Environment="JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk"
Environment="JAVA_OPTS=-Xmx2048m -Djava.awt.headless=true"

After making changes, restart Jenkins and verify:

sudo systemctl restart jenkins
# Check the Java version in Jenkins dashboard:
# Manage Jenkins → System Information → Java Version

If Jenkins fails to start after the change:

  • Verify Java 8 is properly installed: java -version
  • Check file permissions on the new JRE
  • Review Jenkins logs: journalctl -u jenkins -f
  • Ensure no conflicting JAVA_HOME settings in ~/.bashrc or /etc/profile

For systems with multiple Java versions:

sudo update-alternatives --config java
# Select the Java 8 option
# Then reconfigure Jenkins to use system default

Jenkins relies heavily on Java Runtime Environment (JRE) to execute its core processes and plugins. When running as a service on Linux, it typically uses the system's default Java installation unless specifically configured otherwise.

Before making any changes, verify your current setup:

# Check Jenkins Java version
ps -ef | grep jenkins | grep -i java

# Check available Java installations
update-alternatives --config java

The most reliable method is to edit Jenkins' init script:

# For systemd systems (Ubuntu 16.04+, CentOS 7+)
sudo systemctl edit jenkins

# Add these lines:
[Service]
Environment="JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64"

For older systems using init.d:

# Edit the init script
sudo nano /etc/default/jenkins

# Modify these variables:
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"
JAVA_CMD="$JAVA_HOME/bin/java"

If the above methods don't work, consider these options:

1. Update-alternatives method:

sudo update-alternatives --config java
# Select Java 8 from the list

2. Direct JVM parameter modification:

# Edit Jenkins startup parameters
sudo nano /etc/sysconfig/jenkins
# Add or modify:
JENKINS_JAVA_CMD="/path/to/java8/bin/java"

After making changes, always verify:

sudo systemctl daemon-reload
sudo systemctl restart jenkins
# Check version
ps -ef | grep jenkins | grep -i java

Permission problems: Ensure Jenkins user has access to the new Java installation.

Plugin compatibility: Some plugins might require specific JVM arguments even after switching versions.

Log checking: Always examine Jenkins logs after changes:

sudo journalctl -u jenkins -f
# or
sudo tail -f /var/log/jenkins/jenkins.log