Jenkins Installation: A Step-by-Step Guide
Jenkins, a popular open-source automation server, facilitates continuous integration (CI) and continuous delivery (CD) for DevOps teams. It automates various stages of software development, from building to testing, and makes the deployment process more efficient. For those looking to set up Jenkins on a Red Hat-based Linux distribution, this guide walks through the necessary commands, explains their function, and provides a few custom configurations.
Pre-requisites
Before installing Jenkins, ensure your system meets the following requirements:
A Red Hat-based Linux distribution (such as CentOS, RHEL, or Fedora)
Root or sudo privileges
Network access to Jenkins repositories
Java JDK 11 installed
Now, let’s break down the steps:
Step 1: Enable EPEL Repository
The EPEL (Extra Packages for Enterprise Linux) repository contains additional packages not available in the standard repositories.
sudo yum install epel-release -y
- Explanation: This command installs the EPEL repository, making a wider range of software packages available to your system. The
-y
flag ensures automatic confirmation.
Step 2: Install Java JDK 11
Jenkins requires Java to run, specifically JDK 11 in this case.
sudo yum install java-11-openjdk -y
- Explanation: Installs OpenJDK 11, a popular free and open-source version of the Java Platform. Jenkins needs Java to run since it is a Java-based application.
Step 3: Add Jenkins Repository
Jenkins packages aren't included by default in most repositories, so we need to download and add the official Jenkins repository.
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo --no-check-certificate
- Explanation: The
wget
command fetches the Jenkins repository file and saves it in the/etc/yum.repos.d/
directory. The--no-check-certificate
flag bypasses SSL certificate verification.
Step 4: Import Jenkins Key
Jenkins requires a GPG key to validate its packages.
sudo rpm --import http://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
- Explanation: The
rpm --import
command imports the official Jenkins GPG key, ensuring the packages installed from the Jenkins repository are trusted.
Step 5: Install Jenkins
Now that the repository and keys are in place, it's time to install Jenkins.
sudo yum install jenkins -y
- Explanation: Install Jenkins from the repository added in the previous steps. The
-y
flag ensures that any prompts during installation are automatically accepted.
Step 6: Change Jenkins Default Port
By default, Jenkins runs on port 8080. If you need to run Jenkins on another port (e.g., 8090), you'll need to modify the service configuration file.
sudo vi /lib/systemd/system/jenkins.service
- Explanation: This command opens the Jenkins service file using the
vi
editor. You can change the port by updating theJENKINS_PORT
environment variable. Look for this line:
Environment="JENKINS_PORT=8090"
- Modify the value from 8080 to 8090, or any other available port.
Step 7: Start Jenkins
Once the installation and port configurations are complete, you can start the Jenkins service.
sudo systemctl start jenkins
- Explanation: The
systemctl
command is used to control the system's services. In this case,start jenkins
launches Jenkins, making it accessible via the browser on the configured port.
Step 8: Retrieve Jenkins Initial Admin Password
Jenkins requires an admin account to be set up during the first launch. To proceed, you’ll need the initial admin password.
cat /var/lib/jenkins/secrets/initialAdminPassword
- Explanation: This command outputs the content of the
initialAdminPassword
file, which contains the Jenkins admin password for the first-time setup.
Step 9: Customize Jenkins
Once Jenkins is running, open your browser and go to http://your-server-ip:8090
. You will be prompted to log in using the initial admin password. After logging in, you'll see an option to customize Jenkins.
- Choose "Install Suggested Plugins": This option provides a set of commonly used plugins that are recommended for most Jenkins setups.
Conclusion
By following the steps outlined above, you’ll have Jenkins up and running on your Red Hat-based system, ready to automate your CI/CD pipelines. Whether you're managing build environments or deploying applications, Jenkins is a powerful tool in a DevOps engineer's arsenal.
Subscribe to my newsletter
Read articles from Ali Hassan Khan Yousafzai directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Ali Hassan Khan Yousafzai
Ali Hassan Khan Yousafzai
As a DevOps Engineer at Polymer SaaS DLP, I orchestrate seamless deployments for optimal performance, leveraging cloud-native technologies and infrastructure as code (IaC) tools. I have implemented CI/CD pipelines, monitoring and logging solutions, and automated testing frameworks to streamline development and enhance scalability. I have also contributed to resolving complex issues, optimizing resource utilization, and ensuring security and compliance standards.