How to Install Jenkins on Ubuntu 24.04
Jenkins is a tool built with Java that helps development teams automate key tasks throughout the software development process, also known as continuous integration (CI).
With Jenkins, you can change and merge your code with the main codebase and build it into a working application. This will help you catch errors earlier in the development cycle. Jenkins helps development teams work more efficiently and deliver higher-quality software.
Table of Contents:
- How To Install Jenkins on Ubuntu 24.04
- Installing Prerequisite (Java)
- Installing Jenkins
- Starting and Configuring Jenkins on Ubuntu 24.04
- Setting Up the Firewall for Jenkins
- Basic Configuration and User Creation
- How to Uninstall Jenkins from Ubuntu 24.04
- Conclusion
1. How To Install Jenkins on Ubuntu 24.04
To install the latest version of Jenkins in Ubuntu 24.04 you can use the Jenkins official repositories. The Jenkins version found inside the default Ubuntu repository always needs to catch up in terms of version number. To get the latest version of Jenkins, you must add its repository using the GPG key. Now we will cover all these steps for repository adding and after that installation command for setting the Jenkins on Ubuntu 24.04.
2. Installing Prerequisite (Java)
To run Jenkins, you’ll need Java. This guide will use OpenJDK, which provides both the development tools and the runtime environment required by Jenkins.
If Java is missing, install it by following these steps.
First start by updating Ubuntu 24.04 system packages:
sudo apt update
Jenkins supports the Java 8 and 11 versions. If your Ubuntu system has any other version installed, make sure you set these two versions as the default Java version for your system.
To install the OpenJDK Java 8 version, run:
sudo apt install openjdk-8-jdk -y
Similarly, to install the OpenJDK Java 11 version run:
sudo apt install openjdk-11-jdk
Once both Java versions are installed, run the Java version command to confirm:
java --version
3. Installing Jenkins
As described earlier, installing Jenkins from its official repository is recommended due to the availability of the latest Jenkins version.
First, start by importing the GPG key for the Jenkins repository:
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key |sudo gpg --dearmor -o /usr/share/keyrings/jenkins.gpg
The gpg –dearmor flag will convert the imported key to a format that can be easily understandable by apt.
Now we need to add the Jenkins package source to our system’s list of software sources. For that, you can run:
sudo sh -c 'echo deb [signed-by=/usr/share/keyrings/jenkins.gpg] http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
The above command will instruct the package manager to verify the package using the imported GPG key. This will verify the Jenkins packaged authenticity so it doesn’t harm your PC and is downloaded from the official source only.
Next, update system packages so the GPG key gets recognized inside the system configuration file:
sudo apt update
Finally, install Jenkins using the apt install command:
sudo apt install jenkins
To check Jenkins version, run:
Jenkins –version
Now that the Jenkins installation is done, let’s proceed with the Jenkins configuration and create a user in it.
4. Starting and Configuring Jenkins on Ubuntu 24.04
Usually, Jenkins will start automatically after installation. But if it doesn’t, you can easily start it using the systemctl command:
sudo systemctl start jenkins.service
Once you have started the Jenkins service, check its status by running:
sudo systemctl status jenkins
Press Q to exit this window.
If everything works correctly, Jenkins should be running and ready to use.
Note: If Jenkins service is not started yet, run the sudo systemctl enable –now jenkins command to start it.
Modify firewall settings before you can access Jenkins through a web browser to set it up.
5. Setting Up the Firewall for Jenkins
By default, Jenkins uses port 8080 to communicate. Allow traffic on this (8080) port to access Jenkins through the web browser. We’ll use a firewall tool to do this.
If your firewall is already on, this command will open port 8080 for Jenkins:
sudo ufw allow 8080
In case your firewall isn’t running, these commands will first enable it. It allows access for SSH open port 8080 for Jenkins:
sudo ufw allow OpenSSH sudo ufw enable
You can always check the firewall’s status with this command to see if the new rules are applied correctly.
sudo ufw status
This should show that traffic is allowed to port 8080.
6. Basic Configuration and User Creation
Now to configure Jenkins, open your web browser and visit the below link:
http://ip_address_or_domain:8080
Here, replace your server’s IP or domain name.
For example, if running Jenkins on the local host, then you can run:
http://localhost:8080
Now a screen will appear asking you to unlock Jenkins. To unlock Jenkins, you’ll need a special password. In your terminal window, run:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
This will display a long, random password. Copy and paste that password into the web interface and click Continue.
Jenkins offers plugins to extend its functionality. You can choose to install some suggested plugins now or skip this step for later.
The plugin installation will begin.
Once the Jenkins plugin installation is completed, you are required to set up the administrative user.
While you can use the initial password as admin, it’s recommended to create a separate user account with a strong password. Fill username and password on the web interface.
Next, Jenkins will ask you to confirm the URL it should use. This is usually the server’s domain or IP address. Click Save and Finish, and you’ll see a confirmation page.
Click Start using Jenkins. This will get you to the main Jenkins dashboard
The main Jenkins dashboard will look like this.
7. How to Uninstall Jenkins from Ubuntu 24.04
To uninstall Jenkins from Ubuntu, first stop the Jenkins service:
sudo systemctl stop jenkins
After that, remove the Jenkins package using the apt command with the purge option:
sudo apt purge jenkins
If you added a separate Jenkins repository during installation, remove its associated list file:
sudo rm /etc/apt/sources.list.d/jenkins.list
By default, Jenkins stores data in the /var/lib/jenkins directory. You can remove this directory and the cache directory to clean up some space:
sudo rm -rf /var/lib/jenkins/ sudo rm -rf /var/cache/jenkins
Conclusion
Jenkins is an open-source tool for automating the development process of software and applications. It is built using Java. To install Jenkins on Ubuntu, you have to add the Jenkins official repository to your Ubuntu 24.04 system. For this, first, import the GPG key of the Jenkins repository and then add it to the system configuration file. After that, update the system package and install Jenkins using the apt install command. Once the installation is done, connect with your local host network through Jenkins.