Install Jenkins on Ubuntu 18.04

Filed Under: Ubuntu

Jenkins is an open-source automation server based on Java that automates repetitive technical tasks involved in the continuous integration and delivery of software.

In this tutorial, we will show you how you can install the latest version of Jenkins on your Ubuntu 18.04 system. Let’s get started!


Step 1: Install Prerequisites

Jenkins, being an open-souce Java application, requires OpenJDK 8 installed on your system. We can get OpenJDK 8 directly from the apt repositories.

But before that, as always, update any system-critical packages first.

sudo apt update
sudo apt install openjdk-8-jdk

This will install OpenJDK 8 on your system. Now that we have our prerequisites ready, we are ready to download the Jenkins package!


Step 2: Retrieve and add the GPG Public Keys

The latest version of jenkins for Debian based systems is available on this repository.

We can install the necessary packages from this link. But before we download anything, we must verify the public GPG key for this package.

We always need to get the public key for that package so that we know that it is valid. We can then download the required data and install the package securely.

So let’s get the GPG public key for Jenkins, which is available at the link:

https://pkg.jenkins.io/debian/jenkins.io.key

To download the key, we will use the wget command from the Terminal.

wget https://pkg.jenkins.io/debian/jenkins.io.key
Ubuntu Jenkins Download Key
Ubuntu Jenkins Download Key

The downloaded key in my case is called jenkins.io.key. After the public key is downloaded, add it to the system keys using apt-key.

sudo apt-key add jenkins.io.key

We will get an OK response as the output, if this command was successful.

Ubuntu Jenkins Add Key
Ubuntu Jenkins Add Key

Now that we have the necessary requirements and the public key is also added, we can now add the Jenkins repository to our list of sources.


Step 3: Add the Jenkins Repository to the Sources List

We need to add the Jenkins source to our list of sources in the system so that any future updates can occur using that source URL when using apt update.

We need to modify /etc/apt/sources.list.

Use any text editor (like nano, vi, etc) and open /etc/apt/sources.list. I will be using vi editor to edit the file.

Go to the end of the file, and add this line to ensure that we add the repository source link.

deb http://pkg.jenkins.io/debian-stable binary/
Ubuntu Jenkins Add Source Link
Ubuntu Jenkins Add Source Link

Exit the editor, after saving your changes.

Now, we are ready to update the system and install our package!


Step 4: Install Jenkins on Ubuntu

Now that we have our sources with us, we are ready to install Jenkins!

It’s simple. First, we update our system and other critical packages. Then, we fetch and install the latest version of Jenkins from the source link. The package name is jenkins, so we shall install that using apt.

sudo apt update
sudo apt install jenkins

Now, if there aren’t any errors, we will return to our shell prompt, and our install has completed successfully!


Step 5: Verify Jenkins Installation

If Jenkins was installed correctly, it would have then automatically started a Jenkins daemon process. So, we need to use the systemctl command and check if the jenkins service has started or not.

sudo systemctl status jenkins
Install jenkins on ubuntu and start the service
Ubuntu Jenkins Check Status

If the command works as expected, then you will see an output similar to mine, indicating that the jenkins service is active, which means that our installation was indeed successful!

Now, by default, the installation of Jenkins only allows local access to the server. We therefore need to configure the ufw firewall to allow incoming connections to the port of the Jenkins server.


Step 6: Allow incoming connections into Jenkins

Jenkins, by default, runs on port 8080. We must allow the ufw firewall access to this port.

sudo ufw allow 8080

To check whether incoming traffic is allowed on port 8080, we can examine the ufw rules on the corresponding port. using:

sudo ufw status

Your output will look something like this, indicating that incoming connections to 8080 are allowed.

Ubuntu Jenkins Allow Incoming Connections
Ubuntu Jenkins Allow Incoming Connections

Now, we are now ready to access the server using the IP Address of the Ubuntu host machine remotely.


Step 7: Visit the Jenkins Server on the Browser

To set up your installation, visit Jenkins on its default port, 8080, using your server domain name or IP address.

Simply access it remotely using a web browser on any of your machines (client). Type:

http://HOST_IP_OR_DOMAIN:8080

where HOST_IP_OR_DOMAIN represents the public IP Address / name of the current Ubuntu machine running Jenkins server.

You will get the below output, indicating that the server is indeed allowing remote access from a non-local client!

Ubuntu Jenkins Remote Sign In
Ubuntu Jenkins Remote Sign In

To get the password, we need to display the below file on our Ubuntu server:

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

Copy the 32-bit password onto the Administrator password field. Now, we are ready to go!

Ubuntu Jenkins Access Complete
Ubuntu Jenkins Access Complete

Conclusion

In this tutorial, we saw how we can install and setup Jenkins on Ubuntu 18.04 system to be accessed from any remote client machine in just a few simple steps.


Leave a Reply

Your email address will not be published. Required fields are marked *

close
Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages