Monolune

Installing Jenkins on Ubuntu 18.04

Jenkins is an open-source automation server that can automate repetitive software tasks, such as unit tests, integration tests, and continuous delivery. It can also be used as a replacement for cron. Jenkins comes with a web-based GUI, allowing team members to view the status of tasks. It comes with excellent integration with third-party services (such as GitHub) through the use of plugins. In this guide, we will show you the step by step instructions on how to install Jenkins on Ubuntu 18.04 Bionic Beaver.

Basic Requirements

First, you will need to update your package lists:

sudo apt-get update

Then you will need to install apt-transport-https in order to be able to install Jenkins from the repositories provided by the Jenkins project:

sudo apt-get install apt-transport-https

Installing Jenkins

To install Jenkins:

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

What this does is it adds the Jenkins signing key, adds the Jenkins repository listing, updates the package lists, and installs Jenkins.

However, Jenkins will not start up correctly because of an incorrect Java version. If you look in /var/log/jenkins/jenkins.log, the following error message will be there:

Jenkins requires Java 8, but you are running 10.0.1+10-Ubuntu-3ubuntu1 from /usr/lib/jvm/java-11-openjdk-amd64
java.lang.UnsupportedClassVersionError: 54.0
	at Main.main(Main.java:128) 

As the error message says, Java 8 is needed instead of the Java version that is present on the system. To fix this, install Java 8:

sudo apt-get install openjdk-8-jdk

For Jenkins to be able to use the installed Java 8, make Java 8 the default version of Java:

sudo update-alternatives --config java

In the dialog that appears, select the version that has /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java as its path, and restart Jenkins (sudo service jenkins restart).

End result

After this, Jenkins should start up normally. You can check that it is the case by visiting http://localhost:8080, and by looking at the Jenkins logs at /var/log/jenkins/jenkins.log and making sure that there are no fatal errors reported there. Have fun with automation!