Cyber Month Deal - up to 36% OFF

How To Install Jenkins on Ubuntu 22.04

Published on May 5, 2023 Updated on Nov 22, 2024

This guide demonstrates how to install Jenkins on Ubuntu 22.04 server in 6 steps, including the setup. We have given detailed instructions with commands and snapshots to install Jenkins, set up a firewall, install Jenkins plugins, and create an Admin user.

But before that, let’s understand What Jenkins is.

What is Jenkins?

Jenkins is an open-source Java-based continuous integration tool. Continuous integration is a DevOps practice where developers regularly merge their code into a central repository where it is automatically tested, built and deployed. Working this way increases software development speed and helps detect bugs earlier in the code.

What is Jenkins used for?

Jenkins automates software development process by creating a pipeline to build, test and deploy the application. You can run Jenkins on any platform, such as Linux, Windows, or macOS.

Jenkins is a top CI/CD tool because it's free, open-source, modular, and integrates with almost every other DevOps software. Currently, there are more than 1800 plugins that can be used to enhance Jenkins' capabilities and make it more user specific.

Prerequisites

Below are the prerequisites for installing Jenkins on Ubuntu 22.04.

  • Configured Ubuntu 22.04 server with a non-root sudo user and a firewall

Not using Ubuntu 22.04? Check our guide on how to install Jenkins on Ubuntu 24.04.

How to install Jenkins on Ubuntu in 6 steps

Firstly, we need to install Java on Ubuntu 22.04 before installing Jenkins.

Step 1: Install Java

Before you start the installation, we always recommend that you update your Ubuntu packages available. You can do so by using the update command:

sudo apt-get update

apt update

Jenkins is a Java-based application, so you need Java Runtime Environment (JRE) installed on your Ubuntu server. The system must have Java version 8 or higher installed.

Let’s install OpenJDK 11, which is an open-source Java Platform. Use the following command to continue:

sudo apt install openjdk-11-jdk

apt install upenjdk-11-jdk apt install upenjdk-11-jdk

Check the Java version to see if it was installed correctly.

java --version

java --version

Step 2: Add Jenkins repository

Make sure you download the latest stable version of Jenkins. You can use curl command to do so. The command below will add the Jenkins repository GPG key that is used to verify the repository files.

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

Once the GPG key gets added successfully, add the Jenkins repository to the local repository of Ubuntu 22.04 system by using the following 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

Add Jenkins repository

After activating Jenkins repository, run the following command to update apt packages list and let the system know that you have recently added a new repository.

sudo apt update

apt update

Step 3: Install Jenkins

Now that everything is configured, install Jenkins and all its dependencies using apt package manager.

sudo apt install Jenkins

apt install jenkins

Step 4: Start Jenkins

Now that Jenkins and all its dependencies have been installed, let’s start the Jenkins server.

You can start Jenkins by running the following systemctl command:

sudo systemctl start Jenkins

Use the systemctl status command to verify that Jenkins started successfully. You should see active (running) status if you executed all the above commands correctly.

sudo systemctl status jenkins

systemctl status jenkins

If everything went well, you should see Jenkins server in an active state.

Step 5: Configure firewall

After Jenkins has been installed, let’s adjust the firewall settings so that it can be reached from a browser. This will complete the initial setup.

Jenkins is configured to run on port 8080 by default, so you should open that port by using ufw.

sudo ufw allow 8080

ufw allow 8080

Run the commands below to allow ssh and enable ufw:

sudo ufw allow ssh
sudo ufw enable

ufw enable

Check the status of the ufw again to confirm the activation of the new rules. You should see ALLOW actions for the 8080 port.

sudo ufw status

ufw status

The firewall is now configured. You can go ahead and set up Jenkins.

Step 6: Set up Jenkins

To set up Jenkins, go to your browser and open http://localhost:8080 where Jenkins server is running.

The Unlock Jenkins screen will appear as shown below, asking for the administrator password.

Unlocking Jenkins

By default, you will be given a 32-character alphanumeric initial admin password to login into Jenkins dashboard. Later, you can create an admin user and password.

Open a new tab in the terminal and run the command below to get the initial credential to unlock Jenkins.

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

Get initial admin password for Jeknkins

Now copy and paste this password on the “Unlock Jenkins” page in the browser and click on continue.

Next, you need to customize Jenkins and install plugins. You can either select plugins of your choice or install suggested plugins, which are the most widely used plugins by the community.

Customize Jenkins

It may take a couple of minutes to install all suggested plugins.

Getting started with Jenkins

You will be prompted to create your first admin user after installing the plugins. After completing the required fields, click "Save and continue." You also have the option to skip this step and continue as Admin.

Create first admin user

In the next step, you need to mention the Jenkins url where the Jenkins instance will get configured to run. Enter a domain name or ip address with port 8080 and click Save and Finish.

Configure Jenkins instance

You should now get a confirmation message “Jenkins is ready!”. Click Start using Jenkins:

Jenkins is ready

Finally, Jenkins dashboard will open where you can start creating your pipeline jobs.

Jenkins dashboard

You have now successfully installed Jenkins on Ubuntu 22.04.

Conclusion

In this tutorial, you've learned how to install Jenkins on Ubuntu 22.04 server, including configuring the firewall, installing Jenkins plugins, and creating an admin user. You should now be ready to create pipeline jobs and automate your software development processes.

If you found this guide helpful, check out our comprehensive tutorials on how to install PostgreSQL on Ubuntu, how to install MongoDB on Ubuntu, and how to install Docker on Ubuntu 20.04.

Cloud VPS - Cheaper Each Month

Start with $9.99 and pay $0.5 less until your price reaches $6 / month.

Share this article

Related Articles

Published on Aug 21, 2019 Updated on Jun 15, 2023

Can DDoS attacks harm your server and how to prevent them?

DDoS attacks can cause real harm to your system. Learn some practical examples of how to lower the risk and how to prevent ddos attacks.

Read More
Published on Nov 28, 2019 Updated on Aug 8, 2023

Streaming Servers: Everything You Need To Know

What are Live Streaming servers. How do they work? Why do you need a stable and fast network? We will try to cover these topics on our article.

Read More
Published on Jul 8, 2022 Updated on Oct 4, 2023

How to Install and Configure Apache Reverse Proxy Server With SSL/TLS Encryption

This step-by-step guide will explain what a reverse proxy is and show you how to install Apache reverse proxy server with SSL/TLS encryption.

Read More
We use cookies to ensure seamless user experience for our website. Required cookies - technical, functional and analytical - are set automatically. Please accept the use of targeted cookies to ensure the best marketing experience for your user journey. You may revoke your consent at any time through our Cookie Policy.
build: 06ac5732e.831