How to Install Jenkins on CentOS and Ubuntu Server?
By Jithin on July 10th, 2020
Jenkins is a free and open-source automation server that helps in software development. For that, Jenkins provides continuous integration and continuous delivery services. Jenkins is a server-based system that runs with Java servlet containers such as Apache Tomcat. It supports different version control tools such as SVN, Git, CVS, RTC, and more. In this tutorial, We are going to see how to install Jenkins on Ubuntu and CentOS.
Jenkins can execute Apache Ant and Apache Maven-based projects, and this tool is a self-contained automation server. The basic functionality of Jenkins is to execute a pre-defined list of jobs or steps based on time. The functionalities of Jenkins can be extended using different plugins. Jenkins monitor every step that gets executed and stops the process if one of the steps fails. Jenkins then sends out the notification about the status of the process or build.
Steps to Install Jenkins on CentOS 6 or 7
The first step is to update the system packages by running the following command and then reboot the server.
# yum update # shutdown -r now
Log in as a sudo user and install Java by using the ‘yum’ command.
$ sudo yum install java-1.8.0-openjdk-devel
The current version of Jenkins does not support Java 10 or 11, so you can check the Java version by running the below command.
$ sudo java -version
Now, you can enable the Jenkins repository by importing the GPG key using the following ‘curl’ command.
$ curl --silent --location http://pkg.jenkins-ci.org/redhat-stable/jenkins.repo | sudo tee /etc/yum.repos.d/jenkins.repo
Add the Jenkins repository to your system with the following command.
$ sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
After enabling the repository, install the latest stable version of Jenkins by using the ‘yum’ command.
$ sudo yum install jenkins
After installation, start the Jenkins service and then check the status by using the following commands.
$ sudo systemctl start jenkins $ sudo systemctl status jenkins
When you execute the Jenkins status check command, it should see something similar to the following output.
jenkins.service - LSB: Jenkins Automation Server Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled) Active: active (running) since Thu 2018-09-20 14:58:21 UTC; 15s ago Docs: man:systemd-sysv-generator(8) Process: 2367 ExecStart=/etc/rc.d/init.d/jenkins start (code=exited, status=0/SUCCESS) CGroup: /system.slice/jenkins.service
You need to enable Jenkins service to start on system reboot. You can enable the same using the below command.
$ sudo systemctl enable jenkins
This command should prompt something similar to the below output.
jenkins.service is not a native service, redirecting to /sbin/chkconfig. Executing /sbin/chkconfig jenkins on
Next, if you have installed Jenkins on a remote CentOS server, then you need to adjust the firewall port to 8080 by using the following command.
$ sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp $ sudo firewall-cmd --reload
Finally, to set up your Jenkins installation, you need to open the browser and type your domain or IP address, followed by port 8080.
After you hit the above URL, a screen similar to one shown below appear, there you need to enter the Administrator password that we created during the installation and click the ‘Continue’ button.
If you want to print the password on your terminal, then you can execute the following command. It is a 32- character long alphanumeric password, and you can copy the same and paste it in the above screen to continue Jenkins setup.
$ sudo cat /var/lin/jenkins/secrets/initialAdminPassword
In the next screen, you can install either the suggested or specific plugins. If you want to install the suggested plugins, then you can click the ‘Install suggested plugins’ box. The installation process starts automatically.
After the installation completes, you can set up the first administrative user in the next screen and click the ‘Save and Continue’ button.
On the next screen, you can set the URL for Jenkins instances. If you don’t want to change the URL, then you can keep the automatically generated URL and click the ‘Save and Finish’ button.
Finally, you can click the ‘Start using Jenkins’ button. This button redirects you to the Jenkins dashboard as the admin user that you have created in Step 11.
Steps to Install Jenkins On Ubuntu Server
First, update the packages list using the following command.
$ sudo apt-get update
Install Java, and if you have multiple versions installed, then make sure that the default Java version is Java 8.
$ sudo apt-get install -y openjdk-8-jdk
Next, import the GPG key of the Jenkins repository using the ‘wget’ command. This command should output as ‘OK’ to indicate the successful import of the key.
$ wget -q -O – https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
Add the Jenkins repository to the system by using the following command.
$ sudo sh -c ‘echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list’
After the Jenkins repository is enabled, you need to update the apt package and then install the latest version of Jenkins.
$ sudo apt-get update $ sudo apt-get install jenkins
Jenkins automatically start after the installation. You can check the status of the same by running the following command.
$ systemctl status jenkins
After the installation of Jenkins, you need to adjust the firewall to open port 8080. You can use the ‘ufw’ command to manage your firewall. You can then verify the changes by checking the status.
$ sudo ufw allow 8080 $ sudo ufw status
This status command should show the output similar to the one shown below:
Status: active To Action From -- --------- -------- OpenSSH ALLOW Anywhere 808 ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (V6) 8080 (V6) ALLOW Anywhere(V6)
Next, you can set up Jenkins by hitting the below URL in your browser.
Now, you can follow all the steps shown in the setup wizard screen, such as the installation of plugins, create a new admin user, and set the URL for Jenkins instance. Finally, you can click the ‘Save and Finish’ button to complete Jenkins set up.
You can click the ‘Start using Jenkins’ button. This button redirects you to the Jenkins dashboard as the admin user that you have created earlier in the process.
If you need any further help, please do reach our support department.