Tags Archives: Jenkins

Installing Jenkins on Ubuntu

Jenkins is a self-contained open-source automation server used for automating repetitive technical assignments involved in programming, testing, delivering and deploying software.

 

Jenkins is Java-based and can be installed using Ubuntu packages, Docker, or by downloading and running its web application archive (WAR) file that includes all the contents of a web application to run on a server.

 

Prerequisites for Installing Jenkins

 

A minimum 1 GB of RAM for a small team and 4 GB+ of RAM for production-level Jenkins installations.

 

Oracle JDK 11 needs to be installed

 

 

So, first we need to install openjdk:

 

do an apt update first

 

Next, check for Java installation on the system:

 

$ java -version

 

 

If Java is not currently installed, you will get the following output:

 

Command ‘java’ not found, but can be installed with:

 

sudo apt install openjdk-11-jre-headless # version 11.0.10+9-0ubuntu1~20.04, or
sudo apt install default-jre # version 2:1.11-72
sudo apt install openjdk-8-jre-headless # version 8u282-b08-0ubuntu1~20.04
sudo apt install openjdk-13-jre-headless # version 13.0.4+8-1~20.04
sudo apt install openjdk-14-jre-headless # version 14.0.2+12-1~20.04

 

 

root@asus:/home/kevin# apt install default-jdk
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following packages were automatically installed and are no longer required:
daemon libevent-core-2.1-7 libevent-pthreads-2.1-7 libopts25 sntp
Use ‘sudo apt autoremove’ to remove them.
The following additional packages will be installed:
default-jdk-headless default-jre default-jre-headless libxt-dev openjdk-11-jdk openjdk-11-jdk-headless openjdk-11-jre
openjdk-11-jre-headless

 

 

root@asus:/home/kevin# java -version
openjdk version “16.0.1” 2021-04-20
OpenJDK Runtime Environment (build 16.0.1+9-Ubuntu-120.10)
OpenJDK 64-Bit Server VM (build 16.0.1+9-Ubuntu-120.10, mixed mode, sharing)
root@asus:/home/kevin#

 

 

Setting the JAVA_HOME Environment Variable in Ubuntu

Most of the Java-based software programs use the JAVA_HOME environment variable to discover the Java installation location.

 

To set the JAVA_HOME environment variable, first, check where Java is installed by running the following command:

 

$ readlink -f /usr/bin/java

root@asus:/home/kevin# readlink -f /usr/bin/java
/usr/lib/jvm/java-16-openjdk-amd64/bin/java
root@asus:/home/kevin#

 

then do

 

nano /etc/environment

 

Add the following line at the end of the file, make sure to replace the location of your Java installation path.

 

JAVA_HOME=”/usr/lib/jvm/java-16-openjdk-amd64″

then save the file and reload the file to apply the changes to your current session:

 

$ source /etc/environment

Verify that the environment variable is set:

 

$ echo $JAVA_HOME

 

root@asus:~# source /etc/environment
root@asus:~#
root@asus:~#
root@asus:~# echo $JAVA_HOME
/usr/lib/jvm/java-16-openjdk-amd64
root@asus:~#

 

 

Next we can install jenkins!

 

To take advantage of the most recent stable version of Jenkins features and fixes, use the project-maintained packages to install:

 

$ wget -q -O – https://pkg.jenkins.io/debian-stable/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

 

 

 

Jul 18 14:15:19 asus systemd[1]: Starting LSB: Start Jenkins at boot time…
Jul 18 14:15:19 asus jenkins[1382664]: Found an incorrect Java version
Jul 18 14:15:19 asus jenkins[1382664]: Java version found:
Jul 18 14:15:19 asus jenkins[1382686]: openjdk version “16.0.1” 2021-04-20

 

 

Starting LSB: Start Jenkins at boot time
Found an incorrect Java version
Java version found:
openjdk version “16.0.1” 2021-04-20

 

 

Unfortunately, Jenkins does not work with Java version openjdk 16.

 

I switched to Java  version 11 and now it works:

 

root@asus:/etc/init.d# update-alternatives –config java
There are 2 choices for the alternative java (providing /usr/bin/java).

 

Selection Path Priority Status
————————————————————
0 /usr/lib/jvm/java-16-openjdk-amd64/bin/java 1611 auto mode
* 1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
2 /usr/lib/jvm/java-16-openjdk-amd64/bin/java 1611 manual mode

 

Press <enter> to keep the current choice[*], or type selection number:

 

(previously it was 0 ie version 16)

 

 

root@asus:/etc/init.d# systemctl status jenkins
● jenkins.service – LSB: Start Jenkins at boot time
Loaded: loaded (/etc/init.d/jenkins; generated)
Active: active (exited) since Sun 2021-07-18 14:26:36 CEST; 2min 8s ago
Docs: man:systemd-sysv-generator(8)
Process: 1386375 ExecStart=/etc/init.d/jenkins start (code=exited, status=0/SUCCESS)

 

Jul 18 14:26:34 asus systemd[1]: Starting LSB: Start Jenkins at boot time…
Jul 18 14:26:34 asus jenkins[1386375]: Correct java version found
Jul 18 14:26:34 asus jenkins[1386375]: * Starting Jenkins Automation Server jenkins
Jul 18 14:26:34 asus su[1386414]: (to jenkins) root on none
Jul 18 14:26:34 asus su[1386414]: pam_unix(su-l:session): session opened for user jenkins by (uid=0)
Jul 18 14:26:35 asus su[1386414]: pam_unix(su-l:session): session closed for user jenkins
Jul 18 14:26:36 asus jenkins[1386375]: …done.
Jul 18 14:26:36 asus systemd[1]: Started LSB: Start Jenkins at boot time.
lines 1-14

 

You can then call up Jenkins on the machine by using a web-browser and entering the URL: 

 

https://localhost:8080

 

 

 

 

Continue Reading