How To Install Jenkins on Ubuntu 22.04? – LinuxWays
Jenkins is a DevOps Tool written in the Java Programming Language used to enforce CI/CD (Continuous Integration/Continuous Delivery) workflows/pipelines. It assists software developers in automating software building, testing, deployment, and delivery processes. This article will demonstrate the installation, configuration, and setting up of Jenkins on Ubuntu 22.04 LTS.
How to Install Jenkins on Linux/Ubuntu?
To install Jenkins on Ubuntu 22.04, the following steps will be performed:
Step 1: Install Java
Installation of Java is a prerequisite as Jenkins requires Java to run. Java is not pre-installed on Ubuntu 22.04. Additionally, not all versions of Java are compatible with Jenkins. We will install the OpenJDK 17 version of Java as Jenkins does not support the current version of OpenJDK at the time of writing this article, i.e., OpenJDK 20. The following steps are performed to install Java on Ubuntu:
- First, launch the terminal by [Ctrl + Alt + T] and update system repositories by
- To install OpenJDK 17, execute:
$ sudo apt install openjdk-17-jre
Press Y to continue with the installation.
The above image verifies the successful installation of OpenJDK 17.
- Finally, to verify installation, execute:
Step 2: Download Jenkins
The stable version of Jenkins can be downloaded via the curl command from the official website of Jenkins. curl is not pre-installed in Ubuntu and can be installed by
From the above image, it can be seen that the curl is successfully installed.
Next, the following instruction is executed to download Jenkins to the local repository:
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
Step 3: Add Jenkins Repository
Next, the Jenkins Repository is added to the local repository by
https://pkg.jenkins.io/debian-stable binary/ | sudo tee
/etc/apt/sources.list.d/jenkins.list > /dev/null
Step 4: Update System Repositories
After adding Jenkins to the local repository, system repositories are updated by
Step 5: Install Jenkins
To install Jenkins, execute the following command:
$ sudo apt install jenkins
Press Y to continue with the installation.
The above image verifies the successful installation of Jenkins.
Step 6: Enable Jenkins
Execute the following command to enable Jenkins:
$ sudo systemctl enable jenkins
Step 7: Start Jenkins
Next, start Jenkins with systemctl command.
$ sudo systemctl start jenkins
Step 8: Check the Status of Jenkins
The status of Jenkins can be checked by:
$ sudo systemctl status jenkins
The above image shows that Jenkins is active.
Step 9: Configure the Firewall
After activation of Jenkins, the next step is to enable the firewall by executing the following command:
Additionally, to add Jenkins as an exception, allow port 8080 on the firewall.
The above image shows that port 8080 is enabled.
The status of the firewall can be checked by
The above image shows that traffic on port 8080 is allowed.
Step 10: Set up Jenkins
The following steps are performed to set up Jenkins on Ubuntu 22.04.
- Jenkins is accessed by http://ip_address_or_domain:8080 from a web browser by plugging in the server or host IP address. We can find a local host IP by accessing the /etc/host file via the Nano Text editor:
From the above image, we can see that the local IP is 127.0.0.1. Next, this IP is used in the above format and Jenkins can either be accessed by http://localhost:8080 or http://127.0.0.1:8080.
- The link redirects to Jenkins’ “Getting Started”
It can be observed from the image above, that Jenkins is locked. Jenkins can be unlocked by accessing the administrator password.
- The default administrator password of Jenkins is placed in initialAdminPassword file that can be accessed using the cat command :
$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword
- Enter this password in the “Administrator password” field and press “Continue”:
Step 11: Customize Jenkins
In order to use Jenkins effectively, Jenkins can be customized by following steps:
- After unlocking Jenkins, the setup prompts to either proceed with “Installing suggested plugins” or “Select plugins to install”. We will proceed with “Install suggested plugins”. If more plugins are required later, there are options to install plugins later according to user needs.
- The setup installs suggested plugins. This step takes a few minutes.
- After the plugins are installed, First User Admin is created by providing the credentials such as User Name, Password, Full Name, and email address and by pressing “Save and Continue”.
- Next, a Jenkin Instance is configured by providing the address for the server followed by pressing “Save and Finish”.
- Finally, press the “Start using Jenkins” button to launch the Jenkins dashboard.
- Jenkins is successfully installed and ready to be used to create projects.
How to Uninstall Jenkins on Ubuntu 22.04?
Jenkins can be uninstalled from Ubuntu 22.04 via the apt repository by either of the following commands.
$ sudo apt autoremove jenkins #removes unused dependencies
$ sudo apt purge jenkins #removes the package and its associated system-wide configuration files.
For example, a user can utilize the following command to remove Jenkins
$ sudo apt autoremove jenkins
Press Y to continue with the uninstallation process. The uninstallation process will be completed in a few seconds.
Conclusion
To install Jenkins, first install Java, then download Jenkins from the developer page of Jenkins. Next, add the Jenkin repository and update the system repositories. After that execute the “sudo apt install jenkins” command to install Jenkins on Ubuntu 22.04. Then, configure the firewall by allowing port 8080 to add Jenkins as an exception. Finally, the user can access Jenkins by browsing to “http://<ip_address_or_domain>:8080”. This article demonstrated the installation, configuration, and setting up of Jenkins on Ubuntu 22.04 LTS.