How to install and set up Jenkins in Rocky Linux/Alma Linux 9

In this Guide we are going to learn how to install and configure Jenkins in Rocky Linux 9. This will also work for other RHEL 9 derivatives like Alma Linux.

Jenkins is a popular opensource automation tool to perform continuous integration and build automation. Jenkins allows to execute a predefined list of steps, e.g. to compile golang source code to build build binary file. The trigger for this execution can be time or event based.

Possible steps executed by Jenkins are for example:

  • Cloning the code from source control system.
  • execute a command to install dependencies required for the code to run
  • Run tests for the software
  • build the software to get an executable
  • Publish test results
  • publish the resulting binary code

Jenkins monitors the execution of the steps and allows to stop the process, if one of the steps fails. Jenkins can also send out notifications in case of a build success or failure.

Jenkins can be extended by additional plug-ins. For example, you can install plug-ins to support building and testing Android applications.

# Requirements

  • A Linux system with Rocky Linux 9 server (At least 2GB of Ram)
  • A user account with sudo or root privileges
  • Access to a terminal window/command line
  • Recent Java version installed

# Table of content

  1. Ensuring that the system is up to date
  2. Install Java
  3. Install Jenkins
  4. Starting and enabling jenkins
  5. Accessing Jenkins
  6. Optional – Using an Ansible playbook

# 1. Ensuring that the system is up to date

Ensure that the system packages are up to date using this command:

sudo dnf -y update

Next, let us install common packages that we will need in our tutorial

sudo dnf install -y curl vim wget

# 2. Install Java

In this section, we will install java on our system. We will be using the openjdk version of java. In Rocky Linux 8, to check what software provides the java command line, use the following command to search dnf search jdk. Since Jenkins uses Java version 11, we cann filter the result using grep.

# dnf search jdk | grep 11
Last metadata expiration check: 0:03:42 ago on Wed 24 Nov 2021 06:10:29 AM EAT.
java-11-openjdk.x86_64 : OpenJDK 11 Runtime Environment
java-11-openjdk-demo.x86_64 : OpenJDK 11 Demos
java-11-openjdk-devel.x86_64 : OpenJDK 11 Development Environment
java-11-openjdk-headless.x86_64 : OpenJDK 11 Headless Runtime Environment
java-11-openjdk-javadoc.x86_64 : OpenJDK 11 API documentation
java-11-openjdk-javadoc-zip.x86_64 : OpenJDK 11 API documentation compressed in a single archive
java-11-openjdk-jmods.x86_64 : JMods for OpenJDK 11
java-11-openjdk-src.x86_64 : OpenJDK 11 Source Bundle
java-11-openjdk-static-libs.x86_64 : OpenJDK 11 libraries for static linking

We can see that it is jdk 11 is available as java-11-openjdk. Install it using the command

sudo dnf install -y java-11-openjdk java-11-openjdk-devel

Confirm the installed version using this command:

$ java -version
openjdk version "11.0.16" 2022-07-19 LTS
OpenJDK Runtime Environment (Red_Hat- (build 11.0.16+8-LTS)
OpenJDK 64-Bit Server VM (Red_Hat- (build 11.0.16+8-LTS, mixed mode, sharing)

# 3. Install Jenkins

# Add jenkins repository

Jenkins isn’t included in the default CentOS software repositories. Use the following commands to add and import the GPG key to ensure your software is legitimate.

sudo wget -O /etc/yum.repos.d/jenkins.repo
sudo rpm --import

# Install jenkins

If its not yet installed, please use this command to install epel-release. This repo contains some dependencies that our jenkins server needs like daemonize.

sudo dnf install epel-release

Use the following command to install jenkins

sudo dnf install jenkins

# 4. Starting and enabling jenkins

Now that jenkins is installed, let us start it using this command:

sudo systemctl start jenkins

To display the status of the Jenkins service, enter the following:

$ sudo systemctl status jenkins
● jenkins.service - Jenkins Continuous Integration Server
     Loaded: loaded (/usr/lib/systemd/system/jenkins.service; disabled; vendor preset: disabled)
     Active: active (running) since Mon 2022-08-01 20:18:21 UTC; 56s ago
   Main PID: 33676 (java)
      Tasks: 42 (limit: 9952)
     Memory: 357.9M
        CPU: 56.592s
     CGroup: /system.slice/jenkins.service
             └─33676 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080

Aug 01 20:17:51 local-kip-rocky9-srv jenkins[33676]: This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword
Aug 01 20:17:51 local-kip-rocky9-srv jenkins[33676]: *************************************************************
Aug 01 20:17:51 local-kip-rocky9-srv jenkins[33676]: *************************************************************
Aug 01 20:17:51 local-kip-rocky9-srv jenkins[33676]: *************************************************************
Aug 01 20:18:21 local-kip-rocky9-srv jenkins[33676]: 2022-08-01 20:18:21.827+0000 [id=28]        INFO        jenkins.InitReactorRunner$1#onAttained: Completed initi>
Aug 01 20:18:21 local-kip-rocky9-srv jenkins[33676]: 2022-08-01 20:18:21.854+0000 [id=22]        INFO        hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up>
Aug 01 20:18:21 local-kip-rocky9-srv systemd[1]: Started Jenkins Continuous Integration Server.

Please check to ensure that the status is active (running) to know that the installation was successful.

To enable Jenkins on boot, use this:

sudo systemctl enable jenkins

# 5. Accessing the jenkins server

Once installed, open browser and navigate to the jenkins on the url If you are running on a remote server, replace the ip with that server’s ip.

You will be asked to provide an initial password found in this location /var/lib/jenkins/secrets/initialAdminPassword. Get it by running this command on the server.

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Citizix - Jenkins install unlock

Citizix – Jenkins install unlock

From here choose whether you want to install the recommended plugins or choose what you want to install.

Citizix - Cuztomize jenkins

Citizix – Cuztomize jenkins

The last page will allow you to set up some initial configuation for the user who will be using the jenkins server.

Citizix - Jenkins Create First Admin User

Citizix – Jenkins Create First Admin User

# 6. Optional – Using an Ansible playbook

You can use the following playbook to accomplish the same task. Save it to a file like install-jenkins.yaml.
To run the playbook:

  • Ensure ansible is installed. Checkout guide on how to install here.
  • Create a hosts file with connection information
  • Run the command ansible-playbook -i <hosts-file-path> install-jenkins.yaml -vvv
- name: Install jenkins on rocky linux 9
  hosts: jenkins-srv
  become: yes
  gather_facts: False
      - name: Install required packages
            - wget
          state: latest

      - name: Install java
          name: java-11-openjdk
          state: latest

      - name: Add jenkins repository
        shell: |
          wget -O /etc/yum.repos.d/jenkins.repo
          rpm --import
          warn: no

      - name: Install jenkins
          name: jenkins
          state: latest

      - name: Start jenkins service
          name: jenkins
          state: started

      - name: Enable jenkins service
          name: jenkins
          enabled: yes

# Conclusion

We managed to install Jenkins in Rocky Linux 9 server in this guide.

Last updated on Mar 20, 2024 17:19 +0300
comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy