How to Install Jenkins on CentOS 86 min read


Table of Contents
Introduction
Jenkins is a free-to-use open-source automation server. It helps with continuous integration and delivery by automating the parts of the software development process that include building, testing, and deploying. It’s a server-side program that runs in Apache Tomcat or other servlet containers. We’ll learn how to install Jenkins on CentOS 8 in this tutorial.
Note: If you using Ubuntu, then follow our tutorial How to install Jenkins on Ubuntu 20.04.
We must first install Java before we can install Jenkins. To do so, follow the steps below.
Install Java in CentOS 8
1. Execute the below command to install Java
sudo yum install java-1.8.0-openjdk-devel -y
2. Now check the java version with the below command
java -version
The output should look like below


Now we can proceed with the installation of Jenkins.
Install Jenkins on CentOS 8
1. We need to install wget so that we can download the Jenkins repository. Execute the below command to install wget
sudo yum install -y wget
2. Now we can download the Jenkins repository with wget
sudo wget –O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins.io/redhat/jenkins.repo
3. Import the Jenkins key with the below command
sudo rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
4. Now we can install Jenkins
sudo yum install jenkins -y


5. Start and enable Jenkins with the below commands
sudo systemctl start jenkins sudo systemctl enable jenkins
6. Check Jenkins status with the below command
systemctl status jenkins


Note: Press q to come out of the status screen.
You can now use your browser to access your Jenkins dashboard. If you’ve installed Jenkins on your local machine, the Jenkins dashboard can be accessed at http://localhost:8080. If you’ve installed it on a cloud instance, type http://<public ip>:8080 into the address bar.
When you access the dashboard for the first time, you will a screen like below,


7. Go back to the terminal and execute the below command
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
8. A password will be displayed, copy and paste it in the dashboard. In the next screen, click on Install suggested plugins


9. Wait for some time till the plugins are installed. After the plugins are installed, you will see a screen like below


10. Fill in the required details and click on Save and Continue.
11. In the next screen (Instance Configuration), click on Save and Finish. Now you should see the below screen,


12. Click on Start using Jenkins


Done.
Note: When you log into the Jenkins dashboard next time, you will have to use the username and password you created while setting up the Jenkins dashboard.
Set Environment Variables in Jenkins
Once we install Jenkins, it is necessary to set environment variables in Jenkins, for example, the Java environment variable. We need to set the Java path in Jenkins so that our jobs in Jenkins are able to execute without any Java errors. We will also look at how to set Git and Maven environment variables as mostly these three tools only will be used in your Jenkins jobs.
Java setup in Jenkins
First of all, we need to check the Java path in our system. By default, the Java folder will be present at /usr/lib/jvm location. The Java folder name will depend on the version of Java installed in your system. In this tutorial, as per the Java installation step, the path of the Java folder is: /usr/lib/jvm/java-1.8.0-openjdk-devel. So, we will set this path in Jenkins. Follow the below steps,
- In Jenkins -> Manage Jenkins
- Global Tool Configuration
- Click on JDK installations
- Uncheck Install automatically option
- Provide any name such as “jdk1.8” in the Name field and provide the Java path
- Save


Git setup in Jenkins
As we setup Java in Jenkins, similarly we need to set Git in Jenkins. In the same screen (Global tool configurations), provide the Name and path for Git. Usually, git path is: /usr/bin/git. You can execute the below command to check git path in your system
whereis git
Once you get the output, copy the path and set it in Jenkins as below


Maven setup in Jenkins
In the same way, we need to set the Maven path as well in Jenkins. Generally, the maven path is /usr/share/maven in Linux systems. You can check the maven path in your system with the below command
whereis maven
In Jenkins, click on Maven installations and set the maven path as below


If you have installed maven manually in a different folder, provide the path accordingly.