In this tutorial, I’ll show you how to install Jenkins on Ubuntu 16.04 and configure Jenkins. You can also refer to the Jenkins download page to see the instructions.
- Ubuntu 16.04
- Java 7 or 8
Installing Java 8
Java is a prerequisite to run Jenkins. We need to install Java first. Jenkins works best with Java version 7 or 8 but not 9.
Use the following command to install Java version 8.
$ sudo apt install openjdk-8-jre-headless
Add the repository key to the local apt package manager.
$ wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
Next, we need to append the Debian package repository address to the server’s ‘sources.list’
$ echo deb https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list
Next, update the package manager so that apt-get will use newly added repository.
$ sudo apt-get update
Now install Jenkins.
$ sudo apt-get install jenkins
$ sudo systemctl start jenkins
Check the status of the Jenkins using the below command.
$ sudo systemctl status jenkins ● jenkins.service - LSB: Start Jenkins at boot time Loaded: loaded (/etc/init.d/jenkins; bad; vendor preset: enabled) Active: active (exited) since Thu 2018-11-15 05:55:29 UTC; 40min ago Docs: man:systemd-sysv-generator(8) Process: 6353 ExecStart=/etc/init.d/jenkins start (code=exited, status=0/SUCCES Tasks: 0 Memory: 0B CPU: 0 Nov 15 05:55:28 jenkins systemd: Starting LSB: Start Jenkins at boot time... Nov 15 05:55:28 jenkins jenkins: Correct java version found Nov 15 05:55:28 jenkins jenkins: * Starting Jenkins Automation Server jenk Nov 15 05:55:28 jenkins su: Successful su for jenkins by root Nov 15 05:55:28 jenkins su: + ??? root:jenkins Nov 15 05:55:28 jenkins su: pam_unix(su:session): session opened for user j Nov 15 05:55:29 jenkins jenkins: ...done. Nov 15 05:55:29 jenkins systemd: Started LSB: Start Jenkins at boot time. Nov 15 05:59:13 jenkins systemd: Started LSB: Start Jenkins at boot time.
Jenkins runs on port 8080 on the localhost. Use your browser to connect to Jenkins using the below URL
Note: If you are installing Jenkins in a Virtual Machine in a cloud, then use the public IP address of the Virtual Machine provided by your cloud service provider. Also make sure you have updated the cloud provider’s firewall rule setting to allow traffic from external sources to port 8080.
After you connect to the Jenkins server, the browser will display an “Unlock” Jenkins page as shown below.
Use the below command to retrieve the key to unlock Jenkins.
$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword b6e2d139844c47f79dad47285cd3998d $
In the next page, choose the option to “install the suggested plugins”.
It will begin installing the recommended plugins. This will take few minutes to complete.
Next, it will prompt us to add new users to administer the Jenkins server. We can skip this step and continue as an “admin” user using the password we have already provided to login. But, we’ll configure a user named “ganesh” with some credentials, as shown below.
After this is done. We’ll see the “Jenkins is Ready!” screen, as shown below.
Click the “Start Using Jenkins” button to view the Jenkins Main Dashboard.
At this point, Jenkins is successfully installed and configured. You can start adding projects in Jenkins now.