How to Install Jenkins on Ubuntu 22.04 / 20.04

Are you looking for an easy guide on to how to install Jenkins?

The step-by-step guide on this page demonstrates you how to install Jenkins on Ubuntu 22.04 (Jammy Jellyfish) / Ubuntu 20.04.

Automation of tasks can be quite tricky especially where multiple developers are submitting code to a shared repository. Poorly executed automation processes can often lead to inconsistencies and delays. And this is where Jenkins comes in. Jenkins is a free and opensource continuous integration tool that’s predominantly used in the automation of tasks. It helps to streamline the continuous development, testing and deployment of newly submitted code.

Prerequisites

  • Pre-Installed Ubuntu 22.04 / 20.04
  • User with sudo privileges
  • Internet Connectivity

Without much fuss , let’s deep dive into Jenkins installation steps on Ubuntu 22.04/20.04

1) Install Java with apt command

Being a Java application, Jenkins requires Java 8 and later versions to run without any issues. To check if Java is installed on your system, run the command:

$ java --version

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

Check-whether-Java-Installled-Ubuntu

To install Java on your system, execute the command:

$ sudo apt install -y openjdk-17-jre-headless

After the installation, once again verify that Java is installed:

$ java --version

Check-Java-Version-Ubuntu

Perfect! We now have OpenJDK installed. We can now proceed.

2) Install Jenkins via its official repository

With Java installed, we can now proceed to install Jenkins. The second step is to import the Jenkins GPG key from Jenkins repository as shown:

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

Next, configure Jenkins repository to the sources list file echo and tee command.

$ 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

Next, update the system’s package list.

$ sudo apt update

And install Jenkins as follows.

$ sudo apt install jenkins

Install-jenkins-apt-command

Once the installation is complete, Jenkins should start automatically. To confirm this, run the command:

$ systemctl status jenkins

Jenkins-Systemctl-Status-Ubuntu

If by any chance Jenkins is not running, execute the following command to start it.

$ sudo systemctl start jenkins

3) Configure firewall rules for Jenkins

As we have seen, Jenkins natively listens on port 8080, and if you have installed Jenkins on a server with UFW enabled, you need to open that port to allow traffic.

To enable firewall on Ubuntu 22.04 / 20.04 LTS run,

$ sudo ufw enable

To open port 8080 on ufw firewall, run the command:

$ sudo ufw allow 8080/tcp

Then reload the firewall to effect the changes.

$ sudo ufw reload

To confirm that port 8080 is open on the firewall, execute the command:

$ sudo ufw status

Ubuntu-firewall-status-jenkins

From the output, we can clearly see that Port 8080 has been opened on the system.

4) Setup Jenkins with GUI

We are almost done now. The only thing remaining is to set up Jenkins using your favorite browser. So, head over to the URL bar and browse your server’s address as shown:

http://server-IP:8080

To check your server’s IP address, use the ip command.

View-IP-Address-Ubuntu-Linux

You will get the page similar to what we have below prompting you to provide the Administrator’s password. As per the instructions, the password is located in the file:

/var/lib/jenkins/secrets/initialAdminPassword

To view the password, use the cat command as shown:

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

Copy the password and paste it in the text field shown and click the “Continue” button.

Unlock-Jenkins-Page-Ubuntu-Linux

In the next step, select ‘Install suggested plugin‘ for simplicity’s sake.

Install-suggested-Plugins-Jenkins-Ubuntu

Thereafter, the installation of the necessary plugin required by Jenkins will commence.

jenkins-plugins-installation-progress-ubuntu

When the installation of plugins is complete, the installer will take you to the next section where you will be required to create an Admin user and click on the ‘Save and Continue’ button.

Create-Admin-User-Jenkins-Ubuntu

The next step will populate the default URL for your Jenkin’s instance. No action is required, simply click ‘Save and Finish’.

Jenkins-URL-Instance-Configuration

Finally, click on the ‘Start using Jenkins’ button to gain access to Jenkins.

Start-Using-Jenkins-Page-Ubuntu

This ushers you to Jenkin’s dashboard as shown.

Jenkins-Dashboard-Ubuntu-Linux

And there you have it. We have successfully managed to install Jenkins on Ubuntu 20.04 LTS.

Also Read : How to Setup Jenkins on CentOS 8 / RHEL 8

4 thoughts on “How to Install Jenkins on Ubuntu 22.04 / 20.04”

Leave a Comment