Getting Started with Jenkins Part -2 š§ Install Jenkins on Ubuntu 22.04

Install Jenkins on Ubuntu 22.04
In this tutorial, you will learn how to install Jenkins on Ubuntu 22.04, start the development server, and create an administrative user to explore Jenkins automation. By the end of the tutorial, you will have a Jenkins server ready for development deployment.
Step 1 ā Logging in as root
To log into your server, you need the server's public IP address and the password or private key for the root user's account if you installed an SSH key for authentication.
If you're not connected to your server, log in as root using this command. Replace "your_server_ip
" with your server's public IP address:
ssh root@your_server_ip
Step 2 ā Installing Java
Many software applications, such as Tomcat, Jetty, Glassfish, Cassandra, and Jenkins, require Java and the JVM (Java virtual machine).
Installing the Default JRE/JDK
One option for installing Java is to use the version packaged with Ubuntu. By default, Ubuntu 22.04 includes Open JDK 11, which is an open-source variant of the JRE and JDK.
To install the OpenJDK version of Java, first update yourĀ apt
Ā package index:
sudo apt update
Next, check if Java is already installed:
java -version
If Java is not currently installed, youāll get the following output:
Command 'java' not found, but can be installed with:
apt install openjdk-11-jre-headless # version 11.0.20+8-1ubuntu1~22.04, or
apt install default-jre # version 2:1.11-72build2
apt install openjdk-17-jre-headless # version 17.0.8+7-1~22.04
apt install openjdk-18-jre-headless # version 18.0.2+9-2~22.04
apt install openjdk-19-jre-headless # version 19.0.2+7-0ubuntu3~22.04
apt install openjdk-8-jre-headless # version 8u382-ga-1~22.04.1
Execute the following command to install the JRE from OpenJDK 11:
sudo apt install default-jre
The JRE will allow you to run almost all Java software.
Verify the installation with:
java -version
Youāll receive output similar to the following:
openjdk version "11.0.20" 2023-07-18
OpenJDK Runtime Environment (build 11.0.20+8-post-Ubuntu-1ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.20+8-post-Ubuntu-1ubuntu122.04, mixed mode, sharing)
Step 3 ā Installing Jenkins
The version of Jenkins included with the default Ubuntu packages is often behind the latest available version from the project itself. To ensure you have the latest fixes and features, use the project-maintained packages to install Jenkins.
First, add the repository key to your system:
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key |sudo gpg --dearmor -o /usr/share/keyrings/jenkins.gpg
TheĀ gpg --dearmor
Ā command is used to convert the key into a format thatĀ apt
Ā recognizes.
Next, letās append the Debian package repository address to the serverāsĀ sources.list
:
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Ā [signed-by=/usr/share/keyrings/jenkins.gpg]
Ā portion of the line ensures thatĀ apt
Ā will verify files in the repository using the GPG key that you just downloaded.
After both commands have been entered, runĀ apt update
Ā so thatĀ apt
Ā will use the new repository.
sudo apt update
Finally, install Jenkins and its dependencies:
sudo apt install jenkins
Now that Jenkins and its dependencies are in place, weāll start the Jenkins server.
Step 4 ā Starting Jenkins
now that Jenkins is installed, start it by usingĀ [systemctl](https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units)
:
sudo systemctl start jenkins.service
SinceĀ systemctl
Ā doesnāt display status output, weāll use theĀ status
Ā command to verify that Jenkins started successfully:
sudo systemctl status jenkins
If everything went well, the beginning of the status output shows that the service is active and configured to start at boot:
Output
ā jenkins.service - Jenkins Continuous Integration Server
Loaded: loaded (/lib/systemd/system/jenkins.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2022-04-18 16:07:28 UTC; 2min 3s ago
Main PID: 88180 (java)
Tasks: 42 (limit: 4665)
Memory: 1.1G
CPU: 46.997s
CGroup: /system.slice/jenkins.service
āā88180 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
Now that Jenkins is up and running, adjust your firewall rules so that you can reach it from a web browser to complete the initial setup.
Step 5 ā Opening the Firewall
By default, Jenkins runs on portĀ 8080
. Open that port usingĀ ufw
:
sudo ufw allow 8080
Note:Ā If the firewall is inactive, the following commands will allow OpenSSH and enable the firewall:
sudo ufw allow OpenSSH
sudo ufw enable
CheckĀ ufw
ās status to confirm the new rules:
sudo ufw status
Youāll notice that traffic is allowed to portĀ 8080
Ā from anywhere:
Output
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
8080 ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
8080 (v6) ALLOW Anywhere (v6)
With Jenkins installed and a firewall configured, you have completed the installation stage and can continue with configuring Jenkins.
Step 6 ā Setting Up Jenkins
To set up your installation, visit Jenkins on its default port,Ā 8080
, using your server domain name or IP address:Ā http://your_server_ip_or_domain:8080
You should receive theĀ Unlock JenkinsĀ screen, which displays the location of the initial password:

In the terminal window, use theĀ cat
Ā command to display the password:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy the 32-character alphanumeric password from the terminal and paste it into theĀ Administrator passwordĀ field, then clickĀ Continue.
The next screen presents the option of installing suggested plugins or selecting specific plugins:

Weāll click theĀ Install suggested pluginsĀ option, which will immediately begin the installation process.

When the installation is complete, youāll be prompted to set up the first administrative user. Itās possible to skip this step and continue asĀ admin
Ā using the initial password from above, but weāll take a moment to create the user.

Enter the name and password for your user

Youāll receive anĀ Instance ConfigurationĀ page that will ask you to confirm the preferred URL for your Jenkins instance. Confirm either the domain name for your server or your serverās IP address:

After confirming the appropriate information, clickĀ Save and Finish. Youāll receive a confirmation page confirming thatĀ āJenkins is Ready!ā:

ClickĀ Start using JenkinsĀ to visit the main Jenkins dashboard:

At this point, you have completed a successful installation of Jenkins.