Learn how to install Jenkins on Ubuntu 22.04 with our step-by-step guide. Set up Jenkins for CI/CD, secure your server, and optimize your development workflow efficientlybyHasanul Haque Banna

How to Install Jenkins on Ubuntu 22

Introduction

Jenkins is a popular open-source automation server used for continuous integration and continuous delivery (CI/CD). It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery. In this guide, I will walk you through the process of installing Jenkins on Ubuntu 22.04, ensuring that you can leverage its powerful features for your development workflow.

While creating this guide, I've also referenced the official jenkins documentation at Jenkins.io, ensuring you have the most accurate and up-to-date information.

Prerequisites

Before we begin, make sure you have:

  • A server running Ubuntu 22.04
  • A user account with sudo privileges
  • A basic understanding of command-line operations

Step 1: Update Your System

Before installing any new software, it's a good practice to update your system packages. Open a terminal and execute the following commands:

sudo apt-get update && sudo apt-get upgrade -y

Step 2: Install Java and other stuff

Jenkins is a Java-based application, so you need to have Java installed on your system. Jenkins requires Java 11 or newer. To install OpenJDK 11, run:

sudo apt-get install fontconfig openjdk-17-jre -y

The `fontconfig` is not necessary though. That's why I have installed without it.

Blog Post Image by Hasanul Haque Banna

After the installation done let's check it. You can verify the installation by checking the Java version:

Blog Post Image by Hasanul Haque Banna

Step 3: Add Jenkins Repository

Jenkins is not included in the default Ubuntu repositories, so you need to add the Jenkins repository to your system. I am implementing the feature as mentioned in the documentation provided by Jenkins official documentation.

This is the Debian package repository of Jenkins to automate installation and upgrade. To use this repository, first add the key to your system (for the Weekly Release Line):

  sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
    https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key

Then add a Jenkins apt repository entry:

 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

Step 4: Install Jenkins

Now that the repository is added, update your package list and install Jenkins:

sudo apt-get update
sudo apt-get install jenkins -y

Step 5: Start and Enable Jenkins

After the installation is complete, start the Jenkins service and enable it to start on boot:

sudo systemctl start jenkins
sudo systemctl enable jenkins

You can check the status of Jenkins to ensure it is running correctly:

sudo systemctl status jenkins

You should see an output indicating that Jenkins is active and running like below

Blog Post Image by Hasanul Haque Banna

Step 6: Adjust the Firewall

By default, Jenkins runs on port 8080. You need to allow traffic on this port. If you are using UFW (Uncomplicated Firewall), run:

sudo ufw allow 8080
sudo ufw enable

Now that everything is setup let's check the status of Firewall and good to go. Let's check it

Check the ufw status by running the command below

sudo ufw status

You should see that port 8080 is allowed.

Blog Post Image by Hasanul Haque Banna

Step 7: Set Up Jenkins

Open your web browser and navigate to http://your_server_ip:8080. You will see the Jenkins unlock screen.

Blog Post Image by Hasanul Haque Banna

Unlock Jenkins

To unlock Jenkins, you need the initial admin password. Retrieve it by running:

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

Copy the password from the terminal and paste it into the Jenkins unlock screen, then click "Continue".

Conclusion

Congratulations! You have successfully installed Jenkins on your Ubuntu 22.04 server. Jenkins is a powerful tool that can significantly improve your CI/CD pipeline, and with proper setup and security measures, it can serve as a reliable cornerstone of your development process. Explore the vast array of plugins and customization options to tailor Jenkins to your specific needs.

Happy building!