Getting Started with Jenkins Part -2 🐧 Install Jenkins on Ubuntu 22.04

Share this article:
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:

Image

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:

Image

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

Image

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.

Image

Enter the name and password for your user

Image

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:

Image

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

Image

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

Image

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