How to Install Jenkins on Ubuntu 18.04/16.04 LTS

In this article, We are going to perform, How to install Jenkins on Ubuntu 18.04/16.04 LTS.

Introduction

Jenkins is an opensource automation tool which is used for continuous integration. Some of below features of Jenkins

  1. Jenkins can be used as a simple CI server or turned into the continuous delivery hub for any project.
  2. Easy installation
  3. Easy configuration
  4. It provides 400+ Pulgin
  5. Jenkins provides extensible features by adding plugins and distributed by build different projects and testing etc.

Prerequisites

  1. One Ubuntu server 18.04/16.04 LTS
  2. Atleast 1 GB RAM
  3. JDK 1.8 or Higher verison is supported
  4. Open Port 8080

Install JDK on Ubuntu

Please follow below article to download and install Oracle JAVA 8 on Ubuntu 18.04/16.04 LTS Manually.

Download and Install Oracle Java 8 on Ubuntu 18.04/16.04 LTS

OR

We can install OpenJDK 8

$ sudo apt-get update
$ sudo apt install openjdk-8-jdk
To install latest OpenJDK
# sudo apt install default-jdk
To check the java version, Here i have install installed Oracle Java 8 on my system.
$ java -version
Output:
java version "1.8.0_241"

Java(TM) SE Runtime Environment (build 1.8.0_241-b07)

Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)

Step 1: Add Jenkins APT Repository Key

Here We are installing latest stable version of Jenkins, if you want to install older LTS version then visit Jenkins Installation page.

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

Output:

ok

Add the Jenkins repository in system

$ sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

Step 2: Install Jenkins On Ubuntu

Once key and repository added , update the source list

$  sudo apt-get update

While updating Jenkins source list if you are getting below errors.

Error: W: GPG error: https://pkg.jenkins.io/debian-stable binary/ Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 9B7D32F2D50582E6

Error: E: The repository ‘https://pkg.jenkins.io/debian-stable binary/ Release’ is not signed.

As per the above error,  above key is  missing: 9B7D32F2D50582E6.

Syntax:

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys <the key>

Add the missing key

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 9B7D32F2D50582E6

Output:

Executing: /tmp/apt-key-gpghome.M2Ehv2EdIk/gpg.1.sh --keyserver keyserver.ubuntu.com --recv-keys 9B7D32F2D50582E6

gpg: key 9B7D32F2D50582E6: 7 signatures not checked due to missing keys

gpg: key 9B7D32F2D50582E6: public key "Kohsuke Kawaguchi <[email protected]>" imported

gpg: Total number processed: 1

gpg:               imported: 1

Update the Jenkins Source list packages

$ sudo apt update

Output:

Hit:2 http://in.archive.ubuntu.com/ubuntu bionic InRelease

Get:3 http://in.archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]

Ign:1 https://pkg.jenkins.io/debian-stable binary/ InRelease

Get:4 https://pkg.jenkins.io/debian-stable binary/ Release [2,044 B]

Get:5 https://pkg.jenkins.io/debian-stable binary/ Release.gpg [195 B]

Get:6 http://in.archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]

Get:7 http://in.archive.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]

Get:8 https://pkg.jenkins.io/debian-stable binary/ Packages [17.2 kB]

Fetched 271 kB in 1s (339 kB/s)

Reading package lists... Done

Building dependency tree

Reading state information... Done

All packages are up to date.

Now its time to Install Jenkins and its dependencies:

$ sudo apt-get install jenkins

Step 4: Start Jenkins Service

$ sudo systemctl start jenkins
$ sudo systemctl status jenkins

Output:

● jenkins.service - LSB: Start Jenkins at boot time
   Loaded: loaded (/etc/init.d/jenkins; bad; vendor preset: enabled)
   Active: active (exited) since Tue 2019-06-11 10:18:52 IST; 22h ago
     Docs: man:systemd-sysv-generator(8)

Step 5: Add Firewall Rule

Allow port 8080/tcp in Firewall to Access Jenkins from remotely

$ sudo ufw allow 8080

Verify if port is enables

$ sudo ufw status

If you have installed Jenkins on Cloud Instance Allow the Port in Incoming or Network Security Group

Step 6: Configure Jenkins

After installation of Jenkins ,successfully running Jenkins services and we will check on browser by Jenkins default port number 8080. We can browse server IP address or domain  http://ip_address_or_domain_name:8080.

 

How to Install Jenkins on Ubuntu 18.04/16.04 LTS 1

By hitting IP and Port on browser for the first time it will prompt for InitialAdminPassword. ssh server and type below command.

$ sudo cat /var/lib/jenkins/secrets/intialAdminPassword

After entering it will give some key as output. Copy and Paste in the browser and Click “Continue” . Next screen will appear as “Customize jenkins”.

How to Install Jenkins on Ubuntu 18.04/16.04 LTS 2

 

In the above image we select “Install Suggested Plugins”,  and its will prompt another screen to install “suggested plugin”.

How to Install Jenkins on Ubuntu 18.04/16.04 LTS 3

 

When the Installation get successful it will prompt for another page “Create First Admin User”.  On the below page enter username,password,Email.

How to Install Jenkins on Ubuntu 18.04/16.04 LTS 4

 

In the above pic you can create new user and password or you can “Continue as admin“. After configuring everything you will prompt a new page.

How to Install Jenkins on Ubuntu 18.04/16.04 LTS 5

Now click on “Start using Jenkins”.  It will redirect to Jenkins Dashboard:

How to Install Jenkins on Ubuntu 18.04/16.04 LTS 6

With the above step we have installed Jenkins Successfully.

Conclusion

In this article, We have covered, How to install Jenkins on Ubuntu 18.04/16.04 LTS, configure Jenkins, Adding firewall rules to access jenkins externally.

Related Articles

How to install Jenkins on CentOS 8

How to Install Jenkins on Ubuntu 20.04 LTS

Reference:

Jenkins Official Documentation

Sivasai Sagar

I am working as DevOps Engineer and having 5 years of Experience. Likes to share knowledge.

2 thoughts on “How to Install Jenkins on Ubuntu 18.04/16.04 LTS”

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap