9

I tried to install latest stable Jenkins version which supports Java 11. So after installing Java 11(JDK) I got the error from Jenkins that incorrect java version was found.

So uninstalled the Java 11 and tried to install Java 8. While installing java 8, the Jenkins messages incorrect java version repeatedly was coming. So I completely removed both Java 11(JDK) and Java 8(JDK) and made sure no folders are there in /usr/bin and /usr/lib/jvm for both java 11 and java 8. When I installed java 8 the system says JDK 8 installed but im not able to find any java version in my system. Why?

  1. How to set up the JDK 8 for the Jenkins and make it working? Where to find java version?
  2. How to remove Jenkins completely from the system if I need to install everything from scratch? Or any way to reset the Linux to a previous state (before java and Jenkins installed)
  3. How to have/maintain both JDK8 and JDK11 in the system?
Kevin Bowen
  • 19,615
  • 55
  • 79
  • 83

4 Answers4

33

I've just encountered this problem, and it actually looks like an issue in /etc/init.d/jenkins testing for the Java version. I just posted a solution here: https://dorian.fraser-moore.com/works/5054500/ubuntu-and-jenkins-found-an-incorrect-java-version , sharing below for those who find this question as first google hit.

Following a recent update to my Ubuntu 20.04.1 LTS dev server my installation of Jenkins stopped running on boot. Checking systemctl status jenkins.service returned back this set of messages

Nov 13 09:35:43 tattve jenkins[1038744]: Found an incorrect Java version
Nov 13 09:35:43 tattve jenkins[1038744]: Java version found:
Nov 13 09:35:43 tattve jenkins[1038776]: openjdk version "11.0.9.1" 2020-11-04
Nov 13 09:35:43 tattve jenkins[1038776]: OpenJDK Runtime Environment (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04)
Nov 13 09:35:43 tattve jenkins[1038776]: OpenJDK 64-Bit Server VM (build 11.0.9.1+1-Ubuntu-0ubuntu1.20.04, mixed mode, sharing)
Nov 13 09:35:43 tattve jenkins[1038744]: Aborting

Which seemed odd, as jenkins support Java 11 and openJDK, indeed I'd been running that before.

Digging around a bit I noticed the init script in /etc/init.d/jenkins that the script, at lines 56-60, was using SED to extract the version from the java - version command into a numeric value, but the regular expression was a bit to broad

# Which Java versions can be used to run Jenkins
JAVA_ALLOWED_VERSIONS=( "18" "110" )
# Work out the JAVA version we are working with:
JAVA_VERSION=$($JAVA -version 2>&1 | sed -n ';s/.* version "\(.*\)\.\(.*\)\..*".*/\1\2/p;')

It turns out this last line was setting JAVA_VERSION to 11.09 which doesn't match anything in JAVA_ALLOWED_VERSION. I could add 11.09 to JAVA_ALLOWED_VERSIONS to make it run, but a better fix seem to be to fix that permissive sed line. Changing it to:

JAVA_VERSION=$($JAVA -version 2>&1 | sed -n ';s/.* version "\([0-9]*\)\.\([0-9]*\)\..*".*/\1\2/p;')

Did the job. It might help someone else.

[Due Diligence Edit]

It looks like someone has already made a PR for a fix: https://github.com/jenkinsci/packaging/pull/198

DorianFM
  • 430
1

Jenkins required java version

Jenkins work perfectly with the Ubuntu provided openjdk packges. You can even decide which OpenJDK version you prefer:

# headless JRE is enough for Jenkins 
$ sudo apt install openjdk-8-jre-headless

or with JAVA 11

$ sudo apt install openjdk-11-jre-headless

Maintain multible Java version in Ubuntu

The this post on howto maintain multible Java versions.

Install Jenkins (as Debian package from jenkins.io)

There is some very easy documentation on how to install the upstream jenkins Debian packages.

$ wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add
$ sudo bash -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
$ sudo apt update
$ sudo apt-get install jenkins

That should do the trick.

Remove Jenkins

If you are using a packages based Jenkins installation, remove the package with:

$ sudo apt remove jenkins

If you are using the tarball from the Jenkins site, just delete the folder where you installed it.

Simon Sudler
  • 3,931
  • 3
  • 21
  • 34
  • Thanks Simon for taking time to answer. please see the java install command and the output i got. When searched for Java using command "which Java" nothing is displaying. – user7501425 Apr 29 '19 at 17:36
  • im not able to attach the screenshot of command and the output of it here. please let me know how can i do it? – user7501425 Apr 29 '19 at 17:39
  • sudo apt install openjdk-8-jdk Reading package lists... Done Building dependency tree
    Reading state information... Done The following packages were automatically installed and are no longer required: daemon net-tools Use 'sudo apt autoremove' to remove them. Suggested packages: openjdk-8-demo openjdk-8-source visualvm The following NEW packages will be installed:
    – user7501425 Apr 29 '19 at 17:44
  • openjdk-8-jdk 0 upgraded, 1 newly installed, 0 to remove and 14 not upgraded. Need to get 0 B/1,435 kB of archives. After this operation, 1,538 kB of additional disk space will be used. Selecting previously unselected package openjdk-8-jdk:amd64. (Reading database ... 168837 files and directories currently installed.) Preparing to unpack .../openjdk-8-jdk_8u191-b12-2ubuntu0.18.04.1_amd64.deb ... Unpacking openjdk-8-jdk:amd64 (8u191-b12-2ubuntu0.18.04.1) ... Setting up openjdk-8-jdk:amd64 (8u191-b12-2ubuntu0.18.04.1) ... – user7501425 Apr 29 '19 at 17:45
  • update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/appletviewer to provide /usr/bin/appletviewer (appletviewer) in auto mode update-alternatives: using /usr/lib/jvm/java-8-openjdk-amd64/bin/jconsole to provide /usr/bin/jconsole (jconsole) in auto mode – user7501425 Apr 29 '19 at 17:45
  • when i entered "which java" nothing is displayed. /usr/bin doesnt have java. /usr/lib/jvm has java-8-openjdk-amd64/bin but there is no java there...please help me understand this. – user7501425 Apr 29 '19 at 17:48
  • when i entered "whereis java" i got the /usr/share/java folder which has the following jars present gettext.jar java_defaults.mk juh-6.0.7.jar jurt-6.0.7.jar libintl.jar ridl.jar unoloader.jar java-atk-wrapper.jar java_uno.jar juh.jar jurt.jar ridl-6.0.7.jar unoloader-6.0.7.jar – user7501425 Apr 29 '19 at 17:53
  • I tried the following as well..sudo apt install openjdk-8-jre-headless Reading package lists... Done Building dependency tree
    Reading state information... Done openjdk-8-jre-headless is already the newest version (8u191-b12-2ubuntu0.18.04.1). The following packages were automatically installed and are no longer required: daemon libice-dev libpthread-stubs0-dev libsm-dev libx11-dev libx11-doc libxau-dev libxcb1-dev libxdmcp-dev libxt-dev net-tools openjdk-8-jdk-headless x11proto-core-dev x11proto-dev xorg-sgml-doctools xtrans-dev
    – user7501425 Apr 29 '19 at 18:09
  • Use 'sudo apt autoremove' to remove them. 0 upgraded, 0 newly installed, 0 to remove and 14 not upgraded. – user7501425 Apr 29 '19 at 18:09
  • still no use..im not able to find java.."which java" returns nothing.."java -version" returns following....Command 'java' not found, but can be installed with:

    sudo apt install default-jre
    sudo apt install openjdk-11-jre-headless sudo apt install openjdk-8-jre-headless

    – user7501425 Apr 29 '19 at 18:11
  • @user7501425 Please add you comments to your question by editing. It is close to impossible to recover the output from the comment section – Simon Sudler Apr 30 '19 at 06:46
  • thanks Simon.
    1)i removed the openjdk-8-jre-headless and re-installed again..very strange..now its installed properly and "which java" is returning /usr/bin/java..i am confused why its working now.
    2)Should i install openjdk-8-jdk also along with this openjdk-8-jre-headless to run jenkins properly or someother software? or JRE is enough? please advice
    – user7501425 Apr 30 '19 at 17:30
  • no, the headless version is enough for Jenkins. Just start Jenkins at check if is is running properly – Simon Sudler Apr 30 '19 at 21:40
0

Jenkins requires Java 8 jdk to be installed. Check your java version by command $ java -version If you have more than one java installed on your machine use the command $ sudo update-alternatives --config java This will provide a list of java versions on your machines. Use the comands to install jenkins $ sudo apt update $ sudo apt install jenkins

To change the port number to say 9090 please edit using sudo $ sudo vim /etc/default/jenkins 8080 is the most commonly used port Find 8080 and change to 9090 Save the file using :wq for Vim editor Open browser http://localhost:9090 to start config of jenkins

0

I got this error after upgrading java from 8 to 11; because I had manually upgraded my jenkins on ubuntu by swapping in the new war. So, my old install had persisted the /etc/init.d/jenkins file with the bug.

For me the fix was as simple as running the proper apt-get update:

sudo apt-get upgrade jenkins

Which properly replaced all the files to the latest version

fei0x
  • 101
  • 1