How to Install Jenkins on Windows, Ubuntu and CentOS?

A step-by-step Jenkins installation guide.

In this article, we will learn how to install Jenkins on the following operating systems.

  • Windows
  • CentOS
  • Ubuntu

For all the above operating systems, Jenkins installation steps slightly vary, but configuration steps are the same.

What is Jenkins?

is an open-source automation building tool for developers to run around projects and applications. It is used for building and deploying software and application. It is a powerful automation application that allows constant integration and continuous delivery of projects, regardless of the platform you are working on.

Since Jenkins is a Java application, it runs standalone by any machine with a Java Runtime Environment (JRE) installed.

If you are looking to learn Jenkins then check out thisto become a hero from zero.

Prerequisite

JDK8+ is mandatory for all operating systems. So first we need to install JDK8 or higher version. You can download and install it.

Jenkins Installation on Windows

Once JDK is installed and running, we are ready to download and install Jenkins. Clickto download the latest Jenkins MSI package for Windows.

  • Double click on jenkins.msi to begin the installation.
  • Click on Next and then install
  • Click on the Change button if you want to install it in another directory. In this example, we will keep the default option, click Next
  • When done with the installation process, click the Finish button to complete the installation.

As you can see the Jenkins installation in Windows is really easy. Just like any other standard software.

Jenkins Installation on Ubuntu

As mentioned earlier, make sure JDK8+ is installed and running on the Ubuntu machine. If it is not installed execute below command to install it.

sudo apt install default-jdk-headless

:~$ sudo apt install default-jdk-headlessReading package lists... DoneBuilding dependency treeReading state information... DoneThe following NEW packages will be installed: default-jdk-headless0 upgraded, 1 newly installed, 0 to remove and 102 not upgraded.Need to get 1132 B of archives.After this operation, 6144 B of additional disk space will be used.Get:1  bionic-updates/main amd64 default-jdk-headless amd64 2:1.11-68ubuntu1~18.04.1 [1132 B]Fetched 1132 B in 2s (676 B/s)Selecting previously unselected package default-jdk-headless.(Reading database ... 30061 files and directories currently installed.)Preparing to unpack .../default-jdk-headless_2%3a1.11-68ubuntu1~18.04.1_amd64.deb ...Unpacking default-jdk-headless (2:1.11-68ubuntu1~18.04.1) ...Setting up default-jdk-headless (2:1.11-68ubuntu1~18.04.1) ...:~$

To verify Java has been installed successfully, execute the below command:

java -version

:~$ java -versionopenjdk version '11.0.7' 2020-04-14OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu218.04)OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-2ubuntu218.04, mixed mode, sharing):~$

Once it is installed, then we are good to go for Jenkins installation.

Installation Steps:

Step 1 : First, Open command terminal (Ctrl + Alt + T)

Step 2: For installing Jenkins, Let’s adding repository key to the system 

wget -q -O - | sudo apt-key add -

:~$ wget -q -O -  | sudo apt-key add -OK:~$

Step 3: Once the key is added, we need to append the Debian package repos address to the machine.

sudo sh -c 'echo deb binary/ > /etc/apt/sources.list.d/jenkins.list'

Step 4: Now update Ubuntu packages

sudo apt update

:~$ sudo apt updateHit:1  bionic InReleaseGet:2  bionic-updates InRelease [88.7 kB]Ign:3  binary/ InReleaseGet:4  binary/ Release [2044 B]Get:5  binary/ Release.gpg [195 B]Get:6  bionic-backports InRelease [74.6 kB]Get:7  bionic/universe amd64 Packages [8570 kB]Get:8  binary/ Packages [17.6 kB]Get:9  bionic-security InRelease [88.7 kB]Get:10  bionic-security/main amd64 Packages [748 kB]Get:11  bionic-security/main Translation-en [237 kB]Get:12  bionic-security/restricted amd64 Packages [50.8 kB]Get:13  bionic-security/restricted Translation-en [12.3 kB]Get:14  bionic-security/universe amd64 Packages [673 kB]Get:15  bionic-security/universe Translation-en [223 kB]Get:16  bionic-security/multiverse amd64 Packages [7808 B]Get:17  bionic-security/multiverse Translation-en [2856 B]Get:18  bionic/universe Translation-en [4941 kB]Get:19  bionic/multiverse amd64 Packages [151 kB]Get:20  bionic/multiverse Translation-en [108 kB]Get:21  bionic-updates/main amd64 Packages [969 kB]Get:22  bionic-updates/main Translation-en [329 kB]Get:23  bionic-updates/restricted amd64 Packages [60.5 kB]Get:24  bionic-updates/restricted Translation-en [14.7 kB]Get:25  bionic-updates/universe amd64 Packages [1085 kB]Get:26  bionic-updates/universe Translation-en [337 kB]Get:27  bionic-updates/multiverse amd64 Packages [15.9 kB]Get:28  bionic-updates/multiverse Translation-en [6420 B]Get:29  bionic-backports/main amd64 Packages [7516 B]Get:30  bionic-backports/main Translation-en [4764 B]Get:31  bionic-backports/universe amd64 Packages [7484 B]Get:32  bionic-backports/universe Translation-en [4436 B]Fetched 18.8 MB in 58s (327 kB/s)Reading package lists... DoneBuilding dependency treeReading state information... Done102 packages can be upgraded. Run 'apt list --upgradable' to see them.:~$

Step 5: Finally to install Jenkins, execute below command

sudo apt install jenkins

:~$ sudo apt install jenkinsReading package lists... DoneBuilding dependency treeReading state information... DoneThe following additional packages will be installed: daemonThe following NEW packages will be installed: daemon jenkins0 upgraded, 2 newly installed, 0 to remove and 102 not upgraded.Need to get 65.7 MB of archives.After this operation, 66.8 MB of additional disk space will be used.Do you want to continue? [Y/n] YGet:1  bionic/universe amd64 daemon amd64 0.6.4-1build1 [99.5 kB]Get:2  binary/ jenkins 2.235.1 [65.6 MB]Fetched 65.7 MB in 3min 34s (307 kB/s)Selecting previously unselected package daemon.(Reading database ... 29242 files and directories currently installed.)Preparing to unpack .../daemon_0.6.4-1build1_amd64.deb ...Unpacking daemon (0.6.4-1build1) ...Selecting previously unselected package jenkins.Preparing to unpack .../jenkins_2.235.1_all.deb ...Unpacking jenkins (2.235.1) ...Setting up daemon (0.6.4-1build1) ...Setting up jenkins (2.235.1) ...invoke-rc.d: could not determine current runlevelProcessing triggers for systemd (237-3ubuntu10.39) ...Processing triggers for man-db (2.8.3-2ubuntu0.1) ...Processing triggers for ureadahead (0.100.0-21) ...:~$

Jenkins installed successfully. Now we can start Jenkins server.

Step 6: Starting Jenkins throughcommand

sudo systemctl start jenkins

systemctl does not show the output so we can che
ck the status through the below command. Through this command, we can check whether Jenkins is active or not. 

sudo systemctl status jenkins

:~$ sudo systemctl status jenkins● jenkins.service - LSB: Start Jenkins at boot time Loaded: loaded (/etc/init.d/jenkins; generated) Active: active (exited) since Sat 2020-04-04 10:10:19 UTC; 2 months 16 days ago Docs: man:systemd-sysv-generator(8) Tasks: 0 (limit: 4915) CGroup: /system.slice/jenkins.serviceApr 04 10:10:18 ip-172-31-17-25 systemd[1]: Starting LSB: Start Jenkins at boot time...Apr 04 10:10:18 ip-172-31-17-25 jenkins[1984]: Correct java version foundApr 04 10:10:18 ip-172-31-17-25 jenkins[1984]: * Starting Jenkins Automation Server jenkinsApr 04 10:10:18 ip-172-31-17-25 su[2037]: Successful su for root by rootApr 04 10:10:18 ip-172-31-17-25 su[2037]: + ??? root:rootApr 04 10:10:18 ip-172-31-17-25 su[2037]: pam_unix(su:session): session opened for user root by (uid=0)Apr 04 10:10:18 ip-172-31-17-25 jenkins[1984]: mesg: ttyname failed: Inappropriate ioctl for deviceApr 04 10:10:18 ip-172-31-17-25 su[2037]: pam_unix(su:session): session closed for user rootApr 04 10:10:19 ip-172-31-17-25 jenkins[1984]: ...done.Apr 04 10:10:19 ip-172-31-17-25 systemd[1]: Started LSB: Start Jenkins at boot time.:~$

Step 6: Configuring port (Optional)

By default, Jenkins is run on 8080 port, and we need to make this port accessible from anywhere(if it is not accessible).

Let’s open the port : 

sudo ufw allow 8080

We can check the status of the port below the following command: 

sudo ufw status

:~$ sudo ufw status Status: active To Action From-- ------ ---- 8080 ALLOW Anywhere 8080 (v6) ALLOW Anywhere (v6):~$

If the status showing of firewall inactive then run the following command otherwise it is not required 

sudo ufw allow OpenSSH

followed by

sudo ufw enable

Jenkins Installation on CentOS

First, make sure JDK8+ is installed and running on the machine. If it is not installed execute below command to install OpenJDK 8 package.

sudo yum install java-1.8.0-openjdk-devel
[~]$ sudo yum install java-1.8.0-openjdk-develCentOS-8 - AppStream 1.0 kB/s | 4.3 kB 00:04 CentOS-8 - AppStream 397 kB/s | 5.8 MB 00:14 CentOS-8 - Base 3.5 kB/s | 3.9 kB 00:01 CentOS-8 - Extras 547 B/s | 1.5 kB 00:02 Jenkins-stable 6.5 kB/s | 2.9 kB 00:00 Dependencies resolved.================================================================================ Package Arch Version Repository Size================================================================================Installing: java-1.8.0-openjdk-devel x86_64 1:1.8.0.252.b09-3.el8_2 AppStream 9.8 MTransaction Summary================================================================================Install 1 PackageTotal download size: 9.8 MInstalled size: 41 MIs this ok [y/N]: yDownloading Packages:java-1.8.0-openjdk-devel-1.8.0.252.b09-3.el8_2. 531 kB/s | 9.8 MB 00:18 --------------------------------------------------------------------------------Total 507 kB/s | 9.8 MB 00:19 Running transaction checkTransaction check succeeded.Running transaction testTransaction test succeeded.Running transaction Preparing : 1/1 Installing : java-1.8.0-openjdk-devel-1:1.8.0.252.b09-3.el8_2.x86 1/1 Running scriptlet: java-1.8.0-openjdk-devel-1:1.8.0.252.b09-3.el8_2.x86 1/1 Verifying : java-1.8.0-openjdk-devel-1:1.8.0.252.b09-3.el8_2.x86 1/1 Installed products updated.Installed: java-1.8.0-openjdk-devel-1:1.8.0.252.b09-3.el8_2.x86_64 Complete![~]$

To verify Java has been installed successfully, execute the below command

java -version
[~]$ java -versionopenjdk version '1.8.0_252'OpenJDK Runtime Environment (build 1.8.0_252-b09)OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)[~]$

Once it is installed, then we are good to go for Jenkins installation.

Installation Steps

Step 1: First, Open Command Terminal

Step 2: To install Jenkins, First, we need to download and add Jenkins GPG key:

sudo wget -O /etc/yum.repos.d/jenkins.repo 
[~]$ sudo wget -O /etc/yum.repos.d/jenkins.repo  04:29:52--  pkg.jenkins-ci.org (pkg.jenkins-ci.org)... 52.202.51.185, 64:ff9b::34ca:33b9Connecting to pkg.jenkins-ci.org (pkg.jenkins-ci.org)|52.202.51.185|:80... connected.HTTP request sent, awaiting response... 200 OKLength: 85Saving to: ‘/etc/yum.repos.d/jenkins.repo’/etc/yum.repos.d/je 100%[==================>] 85 --.-KB/s in 0s 2020-06-21 04:29:54 (2.61 MB/s) - ‘/etc/yum.repos.d/jenkins.repo’ saved [85/85][~]$

Step 3: After downloading and adding Jenkins GPS key, next  Import Jenkins GPG Key:

sudo rpm --import 

Step 4: Update CentOS packages

sudo yum update
[~]$ sudo yum updateLast metadata expiration check: 0:17:09 ago on Sun 21 Jun 2020 04:21:20 AM PDT.Dependencies resolved.Nothing to do.Complete![~]$

Step 5: After update centos packages, we are ready to install, Jenkins: 

sudo yum install jenkins
[~]$ sudo yum install jenkinsLast metadata expiration check: 0:19:26 ago on Sun 21 Jun 2020 04:21:20 AM PDT.Dependencies resolved.=============================================================================== Package Architecture Version Repository Size===============================================================================Installing: jenkins noarch 2.235.1-1.1 jenkins 63 MTransaction Summary===============================================================================Install 1 PackageTotal download size: 63 MInstalled size: 63 MIs this ok [y/N]: yDownloading Packages:jenkins-2.235.1-1.1.noarch.rpm 172 kB/s | 63 MB 06:16 -------------------------------------------------------------------------------Total 172 kB/s | 63 MB 06:16 Running transaction checkTransaction check succeeded.Running transaction testTransaction test succeeded.Running transaction Preparing : 1/1 Running scriptlet: jenkins-2.235.1-1.1.noarch 1/1 Installing : jenkins-2.235.1-1.1.noarch 1/1 Running scriptlet: jenkins-2.235.1-1.1.noarch 1/1 Verifying : jenkins-2.235.1-1.1.noarch 1/1 Installed products updated.Installed: jenkins-2.235.1-1.1.noarch Complete![~]$

Step 6: Starting Jenkins through systemctl 

sudo systemctl start jenkins

Since systemctl does not show the output so you can check the status through the below command. And through this command, you can check whether Jenkins is active or not. 

sudo systemctl status jenkins
[~]$ sudo systemctl status jenkins[sudo] password for geekflare: ● jenkins.service - LSB: Jenkins Automation Server Loaded: loaded (/etc/rc
.d/init.d/jenkins; generated) Active: active (running) Docs: man:systemd-sysv-generator(8)Jun 20 11:15:22 localhost.localdomain systemd[1]: Starting LSB: Jenkins Automa>Jun 20 11:15:23 localhost.localdomain runuser[1456]: pam_unix(runuser:session)>Jun 20 11:15:33 localhost.localdomain jenkins[1433]: Starting Jenkins [ OK ]Jun 20 11:15:33 localhost.localdomain systemd[1]: Started LSB: Jenkins Automat>Jun 21 04:23:04 localhost.localdomain systemd[1]: Stopping LSB: Jenkins Automa>[~]$

Step 7: Configuring the port(Optional)

By default, Jenkins is run on 8080 port, and we need to make this port accessible from anywhere(only if it is not accessible). Let’s open the port,

sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp
[~]$ sudo firewall-cmd --permanent --zone=public --add-port=8080/tcpsuccess[~]$

After configure port reload firewall the 

sudo firewall-cmd --reload
[~]$ sudo firewall-cmd --reloadsuccess[~]$

Configuring Jenkins

Once Jenkins is installed, it will be running on port 8080,  Let’s configure it by navigating to http://localhost:8080 on our favorite browser.

Step-1: Visit

Step-2: To unlock the Jenkins, copy the administrator password from the file located at

  • For Windows

C:\Program Files (x86)\Jenkins\secrets\initialAdminPassword

  • For CentOS and Ubuntu

/var/lib/jenkins/secrets/initialAdminPassword

Now, paste it in the Administrator password field. Then, click the Continue button.

Step-3: You can install either suggested plugins or you can select plugins depending on your use case. Here, we will install the suggested plugins. 

Step-4: Please wait until all plugin is installed. When installation is done, click on Continue.

Step-5: Create an admin profile for Jenkins. Enter the required details and Click on Save and Continue.

Step-6: We can change the Jenkins URL if required, Let’s keep it default http://localhost:8080. Click Save and Finish to complete the configuration process. Now click on Start Using Jenkins

Finally, the configuration process is done, and the above one is the default, Welcome to Jenkins! page.

The Jenkins configuration step is similar for all OS, except Step 2 where we need to retrieve and enter the administrator password. This password could be retrieved from the file, store at the path shown on to Unlock Jenkins UI.

Conclusion

So the above were steps to install Jenkins on your favorite OS. Next, learn how to create your first.

Jenkins installation is easy and if you are setting up for the remote team then you can either get someand install it yourself or go for.