How to Install Jenkins on Ubuntu 22.04

How to Install Jenkins on Ubuntu 22.04

Are you interested in setting up Jenkins on your Ubuntu machine? If so, you’ve come to the right place!

Jenkins, an open-source automation software, is designed to streamline tasks such as software building, documentation, testing, packaging, and deployment. Built with the Java programming language, Jenkins provides a robust platform for Continuous Integration and Continuous Delivery by offering a wide range of DevOps plugins.

In this comprehensive tutorial, we will walk you through the installation and customization of Jenkins on an Ubuntu system, ensuring a seamless setup experience.

So, without further ado, let’s dive in!

What You’ll Need

Before we dive into the tutorial, ensure that you meet the following prerequisites to install Jenkins:

  • A system running Ubuntu (version 22.04 or later)
  • Java 11 or 17
  • 256 MB of RAM (4 GB+ recommended)
  • 1 GB of drive space (10 GB if running as a Docker container, 50 GB+ recommended)

Once you have the requirements for installing Jenkins in place, we can dive into the steps.

How to Install Jenkins on Ubuntu 22.04: Step-By-Step

Step 1: Install OpenJDK 11

Before we begin the installation of Jenkins, it’s important to ensure that you have Java installed on your device. While some distributions may not include Java by default, we’ll cover the steps to address this requirement.

To ensure a smooth installation process, we recommend using the popular OpenJDK implementation of Java. It offers a reliable and widely supported solution for running Jenkins on your system.

Following along with the steps below:

  1. First, update the package information on your device. By updating it, you ensure that you gain access to the OpenJDK 11 repository if you didn’t have so before. Update it with this command:
sudo apt update
  1. Install OpenJDK version 11 since it’s one of the compatible versions. Install it with this command:
sudo apt install openjdk-11-jre
install openjdk 11 on ubuntu
  1. After installing OpenJDK, you can check the current version of Java on your system to confirm if the installation was successful. To check the current Java version installed, run this command:
java -version
check java version

As seen from the above screenshot, the currently installed version of OpenJDK is 11.0.19.  So that means the installation was a success. You can now move to the next step, which will be installing Jenkins itself.

Step 2: Install Jenkins

Now that we’ve fulfilled all the requirements for installing Jenkins, we can start installing it:

  1. First, you need to get the public key from the Jenkins repository. This key ensures the authenticity and integrity of packages we obtain from that repository. Retrieve the key using this command:
# For LTS release
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null

# For weekly release
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null
download jenkins public key
  1. Now we will generate a repository entry for the Jenkins repository by signing it using the key we got in the previous step. You can do that with this command:
# For LTS release
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

# For weekly release
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
  https://pkg.jenkins.io/debian binary/ | sudo tee \
  /etc/apt/sources.list.d/jenkins.list > /dev/null
generate repository entry for Jenkins
  1. We’ve added the Jenkins repository. However, to make this change take effect, we need to update the software repository cache list. Update the list with this command:
sudo apt-get update
sudo apt get update
  1. We’ve successfully added the Jenkins repository as a software source in the package manager. Now we can easily install and update Jenkins-related packages securely. To install Jenkins, run the below command:
sudo apt-get install jenkins
How to Install Jenkins on Ubuntu 22.04

Note: The Jenkins file is a medium size file, so may take a few minutes to install.

Step 3: Start Jenkins

Once you have completed the installation process, you can start Jenkins and get it up and running on your system.

To start the Jenkins service, open your terminal and execute the following command:

  1. To start the Jenkins service, run this command:
sudo systemctl start jenkins.service
start jenkins service on ubuntu
  1. You should confirm whether the service started or not. You can check the current status of Jenkins for confirmation. Check its status using this command:
sudo systemctl status jenkins
check jenkins status

As you can see from the screenshot above, it’s active and running. So that means the service is working.

  1. There’s one more thing you can do–enable Jenkins so that the service will start at every boot. This saves you the effort to start Jenkins every time you open your device. Enable Jenkins using this command:
sudo systemctl enable jenkins
enable jenkins

Step 4: Add Jenkins as an Exception in the Firewall

If you have a firewall installed on your device, it’s important to configure it to allow Jenkins to establish network connectivity. By adding Jenkins as an exception, you ensure that it can bypass firewall rules and establish the necessary connections.

Here’s how to add Jenkins as an exception to your firewall:

  1. Add Jenkins as an exception by running the following script:
YOURPORT=8080

PERM="--permanent"

SERV="$PERM --service=jenkins"

firewall-cmd $PERM --new-service=jenkins

firewall-cmd $SERV --set-short="Jenkins ports"

firewall-cmd $SERV --set-description="Jenkins port exceptions"

firewall-cmd $SERV --add-port=$YOURPORT/tcp

firewall-cmd $PERM --add-service=jenkins

firewall-cmd --zone=public --add-service=http --permanent

firewall-cmd --reload

In this script, we use the default port used by Jenkins, port 8080. That not may be the case for you. So use the appropriate port number.

With that, we’ve completed the installation of Jenkins. Next, we can start setting it up.

Step 5: Access and Configure Jenkins

Jenkins is running on the default port 8080. Again this may vary depending on your machine, so make sure to use the appropriate port number. We can access it from that port.

  1. Open any web browser and then copy and paste the below URL (remember to change the port to the one you configured during installation):
http://localhost:8080
  1. This will bring you to a page where you need to unlock Jenkins. This is a security step to ensure that Jenkins was set up by the correct admin. You will be asked for a password. Find the password in the /var/lib/jenkins/secrets/initialAdminPassword directory. The easiest way to get the password is to use this command:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
jenkins admin password
  1. Enter the password in the field and press the Continue button.
unlock jenkins using secret password
  1. The next page asks you to install plugins for Jenkins. You have two choices—install community-chosen plugins or manually choose your own. If you already know what you’re going to do with Jenkins, you can manually choose and install plugins. Else, you can install the community-suggested ones. We will go for community-suggested plugins.
install jenkins plugins
  1. If you also went the same route as us, you will see that the plugins are being installed. You can also see the list of plugins from here. Wait for them to finish installing. You can add or remove plugins later.
installing jenkins plugins
  1. On the next page, you need to create an admin user. Enter your credentials and fill up the form. Once done, press the Save and Continue button. You may also skip this step if you want.
create admin user for jenkins
  1. After creating an admin, you will be taken to the Instance Configuration page. Here you can specify the URL you will use for Jenkins resources. We are going to keep it as it is. Then press Save and Finish.
jenkins instance configuration
  1. This will complete your Jenkins setup. In the next window, press the Start using Jenkins button to proceed to the dashboard.
jenkins onboarding

That completes the onboarding process! Once you’ve followed the previous steps successfully, you should be directed to the admin dashboard, as shown in the screenshot below:

jenkins admin dashboard

From here, you can start using Jenkins and customize it as you like.

Congratulations! You have successfully installed and configured Jenkins on your Ubuntu machine.

With Jenkins up and running, you now have the power to automate your software deployment and streamline your development processes.

If this guide helped you, please share it.

Related Posts