Jenkins is the most sought-after tool used for automating software development. The automation software allows you to easily integrate various DevOps stages in your project.

Jenkins has great community support. The best thing about the tool is that it is easy to install and learn on any Linux system. Let’s see how you can install and configure Jenkins on Ubuntu 22.04.

What Is Jenkins?

The leading automation server in the market, Jenkins is a free and open-source system that helps in the building, testing, and deploying stages of software development to achieve fast deployment of applications in a production environment.

With this tool, you can set up a continuous integration and continuous delivery (CI/CD) environment for any combination of languages and source code repositories with the help of pipelines.

Jenkins also has support for Slack. A large team of developers and DevOps engineers require a platform to collaborate in a work environment. For this purpose, it's possible to integrate Jenkins with Slack.

It also offers various plugins that help in building, deploying, and automating any project. According to the Jenkins community, there are around 1,500 plugins available for various applications.

Prerequisites to Install Jenkins on Ubuntu

Before getting started with Jenkins installation, you need to make sure that your system meets the following requirements:

  1. Ubuntu 22.04 server installed
  2. SSH access to the server
  3. A non-root sudo user
  4. Access to Ubuntu's command line
  5. At least 256MB of RAM
  6. 1GB of drive space for solo use
  7. 10GB of drive space if Jenkins runs inside a Docker container
  8. 4GB+ of RAM for group use
  9. 50GB+ of drive space for group use
  10. Java Development Kit 8 or 11
  11. NGINX or Apache installed and configured on Ubuntu Server

If your system fulfills these requirements, you are good to go.

How to Install Jenkins on Ubuntu

Here are the steps to install Jenkins on Ubuntu:

Step 1: Install Java Development Kit 11

Jenkins is written in the Java programming language. For it to function, you either need the latest version of Java Development Kit (JDK) or Java Runtime Environment (JRE).

To install Java Development Kit, it’s recommended to first update and upgrade your Ubuntu system using the following commands:

        sudo apt-get update
sudo apt-get upgrade

Jenkins supports both Java Runtime Environment 8 and 11. You can install Java 11 on your system using this command:

        sudo apt-get install openjdk-11-jdk
    

Now, verify if the correct version of Java has been successfully installed with:

        java -version
    

You will see an output stating that OpenJDK version 11 has been installed.

Step 2: Install Jenkins on Ubuntu

Install Jenkins by issuing the following command:

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

Then type:

        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 the new changes to take effect, run:

        sudo apt-get update
    

Once the changes have been updated, execute the following command to install Jenkins:

        sudo apt-get install jenkins
    

When prompted for confirmation, enter Y and hit Enter to begin the installation process.

Step 3: Start Jenkins on Ubuntu

Once you've installed Jenkins, start the service on Ubuntu with this command:

        sudo systemctl start jenkins.service
    

You can verify the Jenkins service status with:

        sudo systemctl status jenkins
    

If it is running fine, you will see the following output on the terminal:

Terminal is showing Jenkins is active

Step 4: Set UFW Firewall Rules for Jenkins

Jenkins, by default, uses port 8080. To make sure this port is accessible, you need to adjust firewall rules with UFW.

To allow port 8080 to listen to upcoming connections, issue the following command:

        sudo ufw allow 8080
    

If the rules are successfully updated, you will see a confirmation message on the command line stating the same.

Next, enable UFW with this command:

        sudo ufw enable
    

Check the status of UFW by typing:

        sudo ufw status
    

In the output, you will see that port 8080 has been allowed and is actively listening for new connections.

Updated Firewall rules displayed on the terminal

Step 5: Access the Jenkins Dashboard on a Web Browser

To launch and configure Jenkins, open a browser, and enter the IP address of your server in the following format:

        http://ipaddress:8080
    

If you are running Jenkins locally, you can access it using:

        http://localhost:8080
    

To unlock Jenkins, you need to authenticate yourself by providing the password kept in the /var/lib/jenkins/secrets/initialAdminPassword file.

The file permissions don’t allow a normal user to access it as it is a password file. Open the command line and run the following command to become a root user.

        sudo -i
    

Now run the following command to get the password from the file:

        nano /var/lib/jenkins/secrets/initialAdminPassword
    

You will find an alphanumeric code like this:

initial admin password file to access Jenkins is displayed

Copy the code and paste it into the box under Administrator password and click Continue.

Jenkins asking the user to provide admin password to get access

Essential Configurations for Jenkins

After accessing the Jenkins web interface, you need to make some necessary configurations.

1. Install Plugins for Jenkins

Jenkins makes use of plugins for continuous integration. To integrate a particular tool, you need to install the plugins for the particular tool, like HTML Publisher and Amazon EC2.

To install plugins, click on Install suggested plugins.

Jenkins asking the user to install plugins

This is the interface you'll use to install the plugins.

Jenkins is installing plugins

2. Create an Administrator Account for Jenkins

Once you've installed all the necessary plugins, Jenkins will prompt you to create an admin user account. Provide the username, password, and e-mail address to create the admin account.

Jenkins interface to create the first admin user by providing username, email and password

Now click Save and Continue. Once the account is created, you will be ready to use Jenkins. Click on Start using Jenkins to continue:

Jenkins interface is confirming that Jenkins is installed and ready to be used

After the initial configuration, you will be able to access the Jenkins Dashboard.

Jenkins dashboard displayed after getting access

How to Uninstall Jenkins From Ubuntu

When you want to remove Jenkins from Ubuntu, run the following APT command:

        sudo apt remove --purge jenkins
    

Deploy Applications Much Faster With Jenkins on Ubuntu

After the initial configuration of Jenkins, you can begin continuous integration and continuous deployment and monitor pipelines on the Jenkins dashboard. With Jenkins, you can now automate tasks, deploy code, increase code coverage, improve code efficiency, make audits simple, and so much more.

Thanks to Jenkins’ intuitive interface and simple framework, DevOps engineers can now deploy applications more efficiently in production environments.