Jenkins written in java is an open-source automation server. It is used to build, test, and document software projects. It allows you to automate a series of activities in order to complete the continuous integration process. With its user-friendly web-based dashboard, it becomes easier to manage some complicated tasks.
In this guide, we will cover how to install Jenkins on ubuntu 20.04 LTS. You must have sudo privileges in order to install Jenkins on your Ubuntu system.
Step 1: Install Java
For Jenkins to run, you will need to first install Java on your system. Here, we will use OpenJDK which is the open-source implementation of the Java platform. You can install OpenJDK in Ubuntu as follows:
$ sudo apt install openjdk-11-jdk
Enter sudo password. When prompted with the y/n option, press y to carry on. After which the OpenJDk installation will be started on your system.
Once finished, you can verify the installation by executing the command below in the Terminal:
$ java --version
If OpenJDK has been installed, you will see the output like this:
Step 2: Install Jenkins
Jenkins is not available in the Ubuntu repositories. We can install it by adding its repository to the system’s local repositories. Here are the steps to install Jenkins:
1. Download and add Jenkins repository key to your apt keyring. By doing this, your system will trust the added repository. Execute the command below to add the Jenkins repository key.
$ wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
2. Add Jenkins repository to your system local repositories using the command below in the Terminal:
$ sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
3. Update the system’s repository index using this command:
$ sudo apt update
4. Now, to install Jenkins, run the command below in the Terminal:
$ sudo apt install jenkins
Enter sudo password. When prompted with the y/n option, press y to carry on. After which the Jenkins installation will be started on your system.
Once the installation of Jenkins is completed, you can start its service using the command below in the Terminal:
$ sudo systemctl start Jenkins
Then to confirm if the service is running fine, run this command in the Terminal:
$ sudo systemctl status Jenkins
If the service is running fine, you will see active (running) in the output.
Step 3: Adjust Firewall
If you want to access Jenkins from the same system on which it is installed, you don’t need to follow this step. However, if you have installed Jenkins to the system secured by a firewall and you need to access it from another system on the network, you will need to allow connections to port 8080 in the firewall.
To verify if the firewall is running on your Ubuntu system, execute the below command:
$ sudo ufw status
If a firewall is running on your system, you will see the active status in the output.
To allow the connections to port 8080, add a rule in the firewall by executing the below command in the Terminal:
$ sudo ufw allow 8080
Then to verify if the rule has been added to the firewall, execute this command:
$ sudo ufw status
The output below verifies that a rule has been added that allows the connection to port 8080 from anywhere.
Step 4: Post-installation setup wizard
Now you will need to setup Jenkins through a post-installation wizard.
1. Open your web browser and access http://ip-address:8080. Replace ip-address by your system’s IP address where Jenkins is installed.
You will see the following Unlock Jenkins page containing the path of the file containing the password. You will need this password to unlock Jenkins. To find this password, type cat followed by the link displayed on the following page like this:
$ cat /var/lib/jenkins/secrets/initialAdminPassword
The above command will display the password on the Terminal screen. Copy this password and paste it into the Administrator password field in the Unlock Jenkins page. Then click Continue.
Then in Customize Jenkins, click Install suggested plugins if you are not sure what plugins to install. Or click Select plugins to install if you want to manually choose the plugins for installation.
Next, the installation of plugins will be started and you will see the progression in the setup wizard.
Once the installation is finished, the wizard will ask you to create your first admin user. Provide details for the admin user and hit Save and Continue. Alternatively, you can skip this step by clicking Skip and continue as admin. This will continue the setup using the default admin user and the password we have used earlier.
Next, you will see asked to set the preferred URL for the Jenkins instance. If you are okay with the URL showing in the screen, click Save and Finish.
Then click Start using Jenkins.
It will redirect you to the Jenkins Dashboard and now you can start using Jenkins.
Remove Jenkins from Ubuntu
In case you need to uninstall/remove Jenkins, you can do so easily using the command below in the Terminal:
$ sudo apt remove Jenkins
Enter sudo password. When prompted with the y/n option, press y to carry on. After which the Jenkins will be removed from your system.
This is how you can install Jenkins on Ubuntu OS. For further information about Jenkins, visit its official documentation.
Karim Buzdar holds a degree in telecommunication engineering and holds several sysadmin certifications including CCNA RS, SCP, and ACE. As an IT engineer and technical author, he writes for various websites.