How to install Jenkins on Ubuntu 22.04

Jenkins is a continuous integration tool that allows continuous development, testing, and deployment of newly created codes.

Jenkins can be installed through native package systems, Docker, or can be run as a standalone on a machine with a Java Runtime Environment (JRE).

Features of Jenkins

  • Jenkins is easy to install on any platform
  • It has great plugins
  • It is easy to configure to any desired state.
  • It is very extensible through plugins
  • It has a highly distributed architecture. Jenkins works on master-slave architecture.

Jenkins Pipeline

Jenkins Pipeline is suite of plugins which support implementing and integrating continuous delivery pipelines. The following are the stages of Jenkins Pipeline

  • Code commit. This is saving your code to github using git.
  • Build stage
  • Testing stage
  • Release stage
  • Deploy/Deliver stage.

Prerequisites

  • 256 MB of RAM
  • 1 GB of disk space
  • Make sure Java is installed

Installing Jenkins on Ubuntu 22.04

1. Update system repositories

Before we can begin the installation, we need to make sure that our systems are up to date.

$ sudo apt update && apt upgrade -y

2. Install Java (JRE)

Jenkins requires Java to run, so we will require to install openJDK on our machine first. To install java lets first check if we have java installed on our system.

$ java version

If you got not found, then we need to install it before installing Jenkins.

$ sudo apt install openjdk-11-jre -y

The sample output you will get will look like this.

The following additional packages will be installed:
  ca-certificates-java fonts-dejavu-extra java-common libatk-wrapper-java
  libatk-wrapper-java-jni openjdk-11-jre-headless
Suggested packages:
  default-jre fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei
  | fonts-wqy-zenhei
The following NEW packages will be installed:
  ca-certificates-java fonts-dejavu-extra java-common libatk-wrapper-java
  libatk-wrapper-java-jni openjdk-11-jre openjdk-11-jre-headless
0 upgraded, 7 newly installed, 0 to remove and 184 not upgraded.
Need to get 43.8 MB of archives.
After this operation, 180 MB of additional disk space will be used.
Do you want to continue? [Y/n] 

We can check if openjdk 11 is installed once again

$ java -version
openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment (build 11.0.15+10-Ubuntu-0ubuntu0.22.04.1)
OpenJDK 64-Bit Server VM (build 11.0.15+10-Ubuntu-0ubuntu0.22.04.1, mixed mode, sharing)

We are good to start installation of Jenkins

3. Install Jenkins on Ubuntu 22.04

To install jenkins we are going to add it into apt repository, first we are going to add signing key to our repositories.

$ sudo curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null

When you have successfully added the keyring, add Jenkins apt repository using the following command.

$ sudo echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian-stable binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null

The next thing is to update our repositories in order for the changes to take effect.

$ sudo apt update

When updates are complete, we can now install Jenkins using the following command.

sudo apt install jenkins -y

The following will be the sample output you will get

The following additional packages will be installed:
  net-tools
The following NEW packages will be installed:
  jenkins net-tools
0 upgraded, 2 newly installed, 0 to remove and 184 not upgraded.
Need to get 87.9 MB of archives.
After this operation, 92.1 MB of additional disk space will be used.
Do you want to continue? [Y/n]

4. Configuring Jenkins

After you have successfully installed Jenkins, then the next thing to do is to configure it.

Lets start with enabling Jenkins on our system.

$ sudo systemctl enable jenkins 

Start Jenkins with the following command.

$ sudo systemctl start jenkins 

To check the status of Jenkins we use the following command.

$ sudo systemctl status jenkins 

You should be in a position to see the following output.

● jenkins.service - Jenkins Continuous Integration Server
     Loaded: loaded (/lib/systemd/system/jenkins.service; enabled; vendor prese>
     Active: active (running) since Tue 2022-06-28 16:38:44 EAT; 5min ago
   Main PID: 28316 (java)
      Tasks: 43 (limit: 9355)
     Memory: 2.1G
        CPU: 1min 16.555s
     CGroup: /system.slice/jenkins.service
             └─28316 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/jav>

Jun 28 16:38:15 zx-pc jenkins[28316]: This may also be found at: /var/lib/jenki>
Jun 28 16:38:15 zx-pc jenkins[28316]: *****************************************>
Jun 28 16:38:15 zx-pc jenkins[28316]: *****************************************>
Jun 28 16:38:15 zx-pc jenkins[28316]: *****************************************>
Jun 28 16:38:44 zx-pc jenkins[28316]: 2022-06-28 13:38:44.413+0000 [id=30]     >
Jun 28 16:38:44 zx-pc jenkins[28316]: 2022-06-28 13:38:44.441+0000 [id=23]     >
Jun 28 16:38:44 zx-pc systemd[1]: Started Jenkins Continuous Integration Server.
Jun 28 16:38:45 zx-pc jenkins[28316]: 2022-06-28 13:38:45.653+0000 [id=50]     >
Jun 28 16:38:45 zx-pc jenkins[28316]: 2022-06-28 13:38:45.655+0000 [id=50]     >
Jun 28 16:38:45 zx-pc jenkins[28316]: 2022-06-28 13:38:45.663+0000 [id=50]  

5. Unlocking Jenkins

To start configuring Jenkins for the first time, go to your browser and type http://localhost:8080. Wait until Jenkins starts

Jenkins start page
Jenkins start page

To get the Administrator password use the following command.

$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Copy the password and use it. Press next to get the plugins to install.

Jenkins plugins
Jenkins plugins

Click on install suggested plugins for convenience.

Once the plugins have been installed, its now time o set the user

Jenkins Add user. Nextgentips
Jenkins Add user. Nextgentips

Input your credentials and click save and continue.

Jenkins Dashboard. Nextgentips
Jenkins Dashboard. Nextgentips

We have successfully installed Jenkins, proceed to create your new project.

About Mason Kipward

I am a technology enthusiast who loves to share gained knowledge through offering daily tips as a way of empowering others. I am fan of Linux and all other things open source.
View all posts by Mason Kipward →

Leave a Reply

Your email address will not be published.