A Jenkins server is running under Java 1.7 on a linux machine and I need to change it to 1.8 so that I can run a specific plugin.

The Linux machine has a Java 1.8 JDK/JRE installed, but I cant find a way to tell the Jenkins server to use it? I've found guides on Windows servers how to do this, but nothing that relates or transfers to Linux Jenkins servers.

Is there a way to change the JRE used by the Jenkins server on linux?

Like a linux version of this: https://dzone.com/articles/make-jenkins-windows-service


On the Jenkins Main Page, to the Left click "Manage Jenkins." Access "Global Tool Configuration" menu, and under this menu there is a location about half way down that should say "JDK Installations." Click that button and it will open a new menu where you can add an alternate JDK. Once added, you go into the project you want to build and click "Configure." Again, about half way down will be a "JDK" drop down. The new JDK will now appear and you can select it to build your project.

However, if you mean you want the entire service to run from a different VM, that is a little trickier. Jenkins start script is written to try and "guess" your VM so it has easier installation across multiple Linux flavors. Find the start script (Red Hat RPM install places it in /etc/rc.d/init.d/jenkins) and read through it. You'll find a section labelled "candidates" and notice how the loop runs through the possible JVMs that might be on a system. You could edit this list to only be the VM you want to use and then stop/start to force it to use the VM you want. Make sure you copy the script before you edit it, just in case.

| improve this answer | |

Depending on the distribution, you will have one of "/etc/sysconfig/jenkins" or "/etc/default/jenkins".

This will have a property to set the java home location. Usually all the options are commented out to show what the file can configure.

| improve this answer | |

Define the JAVA_HOME variable:

Edit /etc/profile with your favorite text editor.

export JAVA_HOME="path to java"
export PATH=$JAVA_HOME/bin:$PATH


source /etc/profile

in order to apply changes.

| improve this answer | |

This is specific to the Macintosh installer version (for the benefit of those brought here, as I was, by a web search), and the path is specific to the Java version which Jenkins is willing to run, which needs to coexist with the Java version we need to test with. It’s ugly, but less ugly than what was there (a duplicated hard-coded path), or than any other suggestion I could find.

    I added/changed the following to the beginning and end of /Library/Application\ Support/Jenkins/jenkins-runner.sh:

echo $javaBin $javaArgs -jar "$war" $args
exec $javaBin $javaArgs -jar "$war" $args

It certainly would be nicer to have this be a setting in org.jenkins-ci.plist, but that would still require changes to jenkins-runner.sh, so this was the minimal change for our purposes.

| improve this answer | |

One way to accomplish this is editing the startup file: /etc/init.d/jenkins.

The default is to just run java, thus relying on what's in the PATH environment variable. You can specify a custom Java executable by editing the line:




You must then run systemctl daemon-reload in order for the changes to be picked up.

This is what I had to do in order to make Jenkins use Java 8 on a Ubuntu system with Java 11 set as the default. It was not acceptable for me to just apt remove openjdk-11-jdk-headless or update-alternatives --config java and choose Java 8 as the default. The caveat with editing the startup file is that it might be overwritten when Jenkins is updated: I'm going to have to keep an eye on it.

| improve this answer | |

This is for windows users who happen to stumple upon this question (like I did). You need to have the system environment variable JAVA_HOME set.

  1. stop jenkins service
  2. edit in the jenkins base folder edit jenkins.xml - in this line "%JAVA_HOME%\jre\bin\java" change %BASE% to %JAVA_HOME%

    %JAVA_HOME%\jre\bin\java -Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpPort=8080 --webroot="%BASE%\war"

  3. start jenkins

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.