How To Install and Configure Jenkins on Ubuntu 16.04/18.04 LTS

Install and configure jenkins on ubuntu 16.04/18.04 lts

Introduction

Jenkins is an opensource automation server written in Java. It helps to automate part of the software development process. You can use Jenkins as a simple CI (Continuous Integration) server or configure this for the CD (Continuous Delivery) hub for any number of projects. In this article, we will learn how to install Jenkins on the ubuntu 18.04 server.

Jenkins can be installed from Ubuntu packages or by downloading and running its Web application ARchive (WAR) file . To know more about Jenkins visit and check https://www.jenkins.io/

In this tutorial we will install Jenkins by adding its Debian package repository in our server , then using that repository to install the package using apt-get.

Before We Begin

  • Ubuntu 18.04 server and a login user with root privileges
  • Java 1.8 or greater should be installed on the server(if not follow step 1)

Hardware Requirements

Minimum:

  • 256 MB of RAM
  • 1 GB of available disk space (10 GB is recommended for containers)

Recommended:

  • 1 GB of RAM
  • 50 GB+ disk space

Step 1: Install Java

Since Jenkins is a Java application, you’ll need Jave JDK installed. There’s an open-source Java JDK program that’s great and easy to install.To install OpenJDK, run the commands below:

sudo apt update
sudo apt install openjdk-8-jdk
Install and configure jenkins on ubuntu 18.04

This should install openjdk java 8 version on your server.You may install java 9,10,11 also in the same way.

Run $ java -version to verify that you have OpenJDK8 correctly installed.

To know more about java installation and configuration please check our java installation tutorials

Step 2: Add Jenkins Repository

The version of Jenkins included with the default Ubuntu packages is often behind the latest available version from the project itself. In order to take advantage of the latest fixes and features, we’ll use the project-maintained packages to install Jenkins.

Here also we have Long Term Support release and Weekly release. For this tutorial, we will install the Jenkins LTS version. As of now, the LTS version is 2.235.3.

If you want to install Weekly release, the package is a little bit different. You can check out on this link Weekly release for me info.

Note: For this step only, first you need to be root otherwise you will get an error like :

Install and configure jenkins on ubuntu 18.04

First, let’s add the GPG key to our package manager so that it can verify the authenticity of the files

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

If done correctly, the terminal will return the message “OK”.

Install and configure jenkins on ubuntu 18.04

Next, add the Debian package repository for Jenkins to the system’s APT source list:

sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > \ /etc/apt/sources.list.d/jenkins.list'
Install and configure jenkins on ubuntu 18.04

In some articles, you may find that the GPG key added with a weekly release package and repository added with a stable version. In that case, you will get a signing key error.

$ wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

This is wrong because the package added in both steps are different.So be careful to add the same package on both steps .

Step 3: Install Jenkins

Now that Jenkins’ repository has been added to Ubuntu. Next it needs to update `apt’s` cache before moving to Jenkins so that it can refresh the operating system’s repository for the latest packages.

sudo apt-get update

Once your system is updated, execute the command to install Jenkins and all its dependencies using the APT package manager:

sudo apt-get install jenkins
Install and configure jenkins on ubuntu 18.04

The installation process will perform the following tasks:

  • Setup Jenkins as a daemon launched on start
  • Create a Jenkins user to run this service
  • Direct console log output to the file /var/log/jenkins/jenkins.log
  • Populate /etc/default/jenkins with configuration parameters for the launch
  • Set Jenkins to listen on port 8080. Access this port with your browser to start configuration

After installing, Jenkins service will automatically start after the installation process is complete

Step 4:Check jenkins status

Now check our jenkins server status using the command :

sudo systemctl status jenkins

It will give output like as below :

● jenkins.service – LSB: Start Jenkins at boot time
Loaded: loaded (/etc/init.d/jenkins; generated)
Active: active (exited) since Sat 2020-08-01 10:20:52 UTC; 1min 26s ago
Docs: man:systemd-sysv-generator(8)
Tasks: 0 (limit: 1121)
CGroup: /system.slice/jenkins.service

This shows service is active and configured to start at boot

You can also verify jenkins running as :

netstat -tunlp | grep 8080

will get output like below :

tcp6 0 0 :::8080 :::* LISTEN 794 8/java

Install and configure jenkins on ubuntu 18.04

Now that Jenkins is running, we’ll adjust our firewall rules so that we can reach Jenkins from a web browser to complete the initial set up.

Step 5 — Opening the Firewall

By default, Jenkins runs on port 8080, so we’ll open that port using ufw:

sudo ufw allow 8080

Since I am installing jenkins server on aws ubuntu instance ,open port 8080 from security groups.

Step 6— Setting up Jenkins

To set up our installation, we’ll visit Jenkins on its default port, 8080, using the server domain name or IP address: http://ip_address_or_domain_name:8080

We should see “Unlock Jenkins” screen, which displays the location of the initial password

Install and configure jenkins on ubuntu 18.04

In the terminal window, we’ll use the cat command to display the password:

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Install and configure jenkins on ubuntu 18.04

We’ll copy the 32-character alphanumeric password from the terminal and paste it into the “Administrator password” field, then click “Continue”. The next screen presents the option of installing suggested plugins or selecting specific plugins.

Install and configure jenkins on ubuntu 18.04

We’ll click the “Install suggested plugins” option, which will immediately begin the installation process:

Install and configure jenkins on ubuntu 18.04

When the installation is complete, we’ll be prompted to set up the first administrative user. It’s possible to skip this step and continue as admin using the initial password we used above, but we’ll take a moment to create the user.

Install and configure jenkins on ubuntu 18.04

Once the first admin user is in place, you should see a “Jenkins is ready!” confirmation screen.

Install and configure jenkins on ubuntu 18.04

Click “Start using Jenkins” to visit the main Jenkins dashboard:

Install and configure jenkins on ubuntu 18.04

You can see our Jenkins version on the bottom of the UI as it shows the current stable version 2.235.3 LTS

Step 7 :Login as Jenkins user

Jenkins installation automatically create jenkins user .We can login as jenkins user by:

sudo -iu jenkins
Install and configure jenkins on ubuntu 18.04

Home folder of Jenkins in ubuntu server is /var/lib/jenkins

Conclusion

In this tutorial, we’ve installed Jenkins server stable version using the project-provided packages, started the server, opened the firewall, and created an administrative user.We also logged in as Jenkins user.

Leave a Reply