How to Install Jenkins on CentOS or Rocky Linux

December 5, 2024

Introduction

Jenkins is an open-source software package for continuous software development. It is used to automate parts of the build, testing, delivery, and deployment of applications. Jenkins is based on Java and facilitates every part of the software development process.

This guide will show you how to install Jenkins on CentOS or Rocky Linux.

How to install Jenkins on CentOS or Rocky Linux - a tutorial.

Prerequisites

Step 1: Install Java

Jenkins is a Java-based application that requires the Java Development Kit to be installed on your system. The latest stable Java JDK version available in the repository at the time this article was written is Java OpenJDK 17. If you already have the latest Java version installed and set as the default, skip ahead to Step 2.

Follow the steps below to install Java:

1. Open the terminal and update the system package repository information:

sudo yum update

2. Install the latest Java OpenJDK version.

sudo yum install java-devel -y

The system scans the repositories, downloads, and installs the latest stable Java version.

Install latest Java version on Rocky Linux.

3. Verify that Java installed successfully by checking the program version:

java --version
Verify Java installation by checking the program version.

Step 2: Add Jenkins Software Repository

Jenkins is not included in the default CentOS software repositories. Follow the steps below to add the Jenkins repository:

1. Open the terminal and run the command below to add the repository:

sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo

The system reaches out to the Jenkins server and downloads the repository location to your system. The output should be similar to this:

Adding Jenkins repository to Rocky Linux.

If the repository download fails, you can add it manually. Run the following command to edit the Jenkins repository config file:

sudo nano /etc/yum.repos.d/jenkins.repo

Paste the following lines in the file:

[jenkins]
name=Jenkins-stable
baseurl=http://pkg.jenkins.io/redhat
gpgcheck=1

2. Save the file and exit to apply the changes.

3. Import the GPG key to ensure your software is legitimate:

sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key

If the process is successful, the system returns a new command line without error.

Note: You may have noticed that the repository lists Red Hat, but your system is CentOS or Rocky Linux. This is because they are based on the Red Hat Linux architecture.

Step 3: Install Jenkins on CentOS or Rocky Linux

After adding the repository, install Jenkins with the following command:

sudo yum install jenkins -y
Jenkins installation complete.

Wait for the process to complete. If you receive an error saying “jenkins not found,” go back and manually add the repository as outlined in the previous step.

Start Jenkins Service

To start the Jenkins service and enable it at startup, run the following commands:

sudo systemctl start jenkins
sudo systemctl enable jenkins

Check the Jenkins service status with:

sudo systemctl status jenkins
Checking the Jenkins service status after installation.

If everything works correctly, the status message should be active (running). Press q to go back to the terminal.

Step 4: Set Firewall to Allow Jenkins

The Jenkins service uses port 8080 to communicate. If you are using the default firewalld service, enter the following commands to allow access:

sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp

sudo firewall-cmd --reload

The system reports success for each command:

Setting firewall rules to allow Jenkins.

If you are using a different firewall, follow its instructions to allow TCP traffic on port 8080.

Step 5: Run and Set up Jenkins

Next, we must test the system to ensure Jenkins is working correctly. Follow the steps below:

1. Open a web browser and enter the following URL:

http://localhost:8080

If your server is remote or has a specific hostname, domain name, or IP address, use that instead.

The browser should display an Unlock Jenkins page.

Testing Jenkins after installation.

2. The password you need to unlock Jenkins was created automatically (but not displayed) during setup. To find it, switch to a terminal window and enter the following:

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

The location is displayed on the Getting Started / Unlock Jenkins page.

The terminal output displays an alphanumeric code. Copy this code and paste it into the password field. Then click Continue.

Unlock Jenkins with administrator password.

3. Jenkins prompts you to install plugins. It is recommended that you Install suggested plugins. You can always change or customize plugins later.

Install Jenkins plugins.

Wait for the process to complete.

4. Once plugins are configured, create the first Admin user. Enter the required details: username, password, confirm the password, and provide the email you want to use for your Jenkins Admin. Click Save and Continue to continue with the configuration.

Create the first admin user in Jenkins.

5. The last page allows you to configure the Jenkins instance. This shows the Jenkins hostname. It is usually the same hostname you used to access the Getting Started page. If you do not create an admin user, there will be a warning.

Enter the URL or keep the default one and click Save and Finish to start using Jenkins.

The instance configuration page in Jenkins.

6. After you complete the Jenkins configuration, the Jenkins dashboard appears, where you can create new jobs.

Jenkins dashboard homepage where you can start new jobs.

Note: Refer to phoenixNAP's Jenkins tutorial for beginners to learn all you need to know about Jenkins.

Conclusion

This tutorial showed how to install and configure Jenkins on your CentOS or Rocky Linux system. If you follow the steps in this guide, your Jenkins dashboard should load properly, and you can start creating jobs.

If you are using a different distribution of Linux, we also have a guide on how to install Jenkins on Debian 10, and how to install Jenkins on Ubuntu.

Was this article helpful?
YesNo
Bosko Marijan
Having worked as an educator and content writer, combined with his lifelong passion for all things high-tech, Bosko strives to simplify intricate concepts and make them user-friendly. That has led him to technical writing at PhoenixNAP, where he continues his mission of spreading knowledge.
Next you should read
How to Install Jenkins on Debian 10 (Buster)
June 15, 2020

If you are a software developer working on a Debian 10 Buster you may want to install Jenkins. Jenkins is...
Read more
How to Install Hadoop on Ubuntu 18.04 or 20.04
September 11, 2024

This detailed guide shows you how to download and install Hadoop on a Ubuntu machine. It also contains all...
Read more
How to Install Jenkins on Ubuntu 18.04
October 20, 2022

Learn how to install Jenkins on Ubuntu 18.04. This software package is used to automate parts of the build...
Read more
How to Install Jenkins on Kubernetes Cluster
December 5, 2024

Use a provided set of YAML files to deploy scalable Jenkins on Kubernetes in 4 easy steps. Use Jenkins to...
Read more