How to Install Jenkins on Ubuntu 20.04

Introduction

Jenkins is a popular self-contained open-source automation application for automating repetitive technical tasks in the development, testing, and delivery or deployment of software. It helps in continuous integration and distribution by automating the sections of software development related to building, testing, and deploying. Jenkins is a server-side application that runs in servlet containers like Apache Tomcat. It was created by Kohsuke Kawaguchi while working at Sun Microsystems. Jenkins was initially called ‘Hudson’ which was created in 2004 and the first release was in 2005. Jenkins is a Java-based application that may be installed using Ubuntu packages or by downloading and running its web application archive (WAR) file, which contains all of the components of a web application to execute on a server. In this tutorial, we will learn how to install Jenkins on Ubuntu 20.04.

You can follow the same steps for the earlier versions of Ubuntu as well. These steps are not specific to only Ubuntu 20.04.

Note: If you are using CentOS, then follow our tutorial How to install Jenkins on CentOS 8.

To install Jenkins, first we need to install Java. Follow the below steps for the same,

Installing Java

1. Execute the below commands to install Java. Jenkins is a Java application, thus you’ll need JDK 8 also called as Java 1.8 on your PC.

sudo apt update
sudo apt install openjdk-8-jdk -y

Note: As of now, Jenkins only supports Java 1.8 and Java 11.

2. Now check the java version with the below command,

java -version

The output should look like below

Tutorial on how to Install Jenkins on Ubuntu 20.04 - Installing Java in Ubuntu

Now we can proceed with the installation of Jenkins.

Install Jenkins on Ubuntu 20.04

1. We need to install wget so that we can download the Jenkins key

sudo apt install -y wget

2. Now download the Jenkins key with the below command

wget -q -O - http://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -

3. Add the Jenkins package URL in the sources file with the below command

sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
Tutorial on how to Install Jenkins on Ubuntu 20.04 -  Add the Jenkins package URL in the sources file

4. Execute the below commands to Install Jenkins

sudo apt update
sudo apt install jenkins -y

5. Execute the below commands to start and enable Jenkins

sudo service jenkins start
sudo service jenkins enable

6. Verify if Jenkins is installed successfully by checking the Jenkins status with the below command

sudo service jenkins status
installed jenkins on ubuntu

Note: Press q to come out of the status screen.

Now you can access your Jenkins dashboard on your browser. If you have installed it in your local system, then you can enter the URL: http://localhost:8080 for the Jenkins dashboard. If you have installed it on a cloud instance, then you can enter the URL: http://<public_ip>:8080

When you access the Jenkins Dashboard for the first time, you will a screen like below,

Jenkins Dashboard setup

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. When everything is successful, you will see the below screen,

12. Click on Start using Jenkins and you will see the Jenkins Dashboard as below,

Tutorial on how to Install Jenkins on Ubuntu 20.04 - Jenkins Dashboard

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 dashboard.

Now you will need to set the environment variables in Jenkins for Java, Git, and Maven. We have covered these tools only as they are mostly used in Jenkins. You can refer to the section: Set Environment Variables in Jenkins for this.


Share:

Leave a Reply