Tutorial

How To Install Jenkins on Ubuntu 16.04

Updated on November 29, 2017
How To Install Jenkins on Ubuntu 16.04
Not using Ubuntu 16.04?Choose a different version or distribution.
Ubuntu 16.04

Introduction

Jenkins is an open source automation server intended to automate repetitive technical tasks involved in the continuous integration and delivery of software. Jenkins is Java-based and can be installed from Ubuntu packages or by downloading and running its Web application ARchive (WAR) file — a collection of files that make up a complete web application which is intended to be run on a server.

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

Prerequisites

To follow this tutorial, you will need:

One Ubuntu 16.04 server configured with a non-root sudo user and a firewall by following the Ubuntu 16.04 initial server setup guide. We recommend starting with at least 1 GB of RAM. See Choosing the Right Hardware for Masters for guidance in planning the capacity of a production Jenkins installation.

When the server is set up, you’re ready to follow along.

Step 1 — Installing Jenkins

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.

First, we’ll add the repository key to the system.

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

When the key is added, the system will return OK. Next, we’ll append the Debian package repository address to the server’s sources.list:

  1. echo deb https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list

When both of these are in place, we’ll run update so that apt-get will use the new repository:

  1. sudo apt-get update

Finally, we’ll install Jenkins and its dependencies, including Java:

  1. sudo apt-get install jenkins

Now that Jenkins and its dependencies are in place, we’ll start the Jenkins server.

Step 2 — Starting Jenkins

Using systemctl we’ll start Jenkins:

sudo systemctl start jenkins

Since systemctl doesn’t display output, we’ll use its status command to verify that it started successfully:

  1. sudo systemctl status jenkins

If everything went well, the beginning of the output should show that the service is active and configured to start at boot:

Output
● jenkins.service - LSB: Start Jenkins at boot time Loaded: loaded (/etc/init.d/jenkins; bad; vendor preset: enabled) Active:active (exited) since Thu 2017-04-20 16:51:13 UTC; 2min 7s ago Docs: man:systemd-sysv-generator(8)

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 3 — Opening the Firewall

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

  1. sudo ufw allow 8080

We can see the new rules by checking UFW’s status.

  1. sudo ufw status

We should see that traffic is allowed to port 8080 from anywhere:

Output
Status: active To Action From -- ------ ---- OpenSSH ALLOW Anywhere 8080 ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) 8080 (v6) ALLOW Anywhere (v6)

Note: If the firewall is inactive, the following commands will make sure that OpenSSH is allowed and then enable it.

  1. sudo ufw allow OpenSSH
  2. sudo ufw enable

Now that Jenkins is installed and the firewall allows us to access it, we can complete the initial setup.

Step 4 — 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

Unlock Jenkins screen

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

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

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.

Customize Jenkins Screen

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

Jenkins Getting Started Install Plugins Screen

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.

Note: The default Jenkins server is NOT encrypted, so the data submitted with this form is not protected. When you’re ready to use this installation, follow the guide How to Configure Jenkins with SSL using an Nginx Reverse Proxy. This will protect user credentials and information about builds that are transmitted via the Web interface.

Jenkins Create First Admin User Screen

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

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

Welcome to Jenkins Screen

At this point, Jenkins has been successfully installed.

Conclusion

In this tutorial, we’ve installed Jenkins using the project-provided packages, started the server, opened the firewall, and created an administrative user. At this point, you can start exploring Jenkins.

When you’ve completed your exploration, if you decide to continue using Jenkins, follow the guide, How to Configure Jenkins with SSL using an Nginx Reverse Proxy in order to protect passwords, as well as any sensitive system or product information that will be sent between your machine and the server in plain text.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about us


About the authors

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
10 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

The Ubuntu droplet doesn’t have JRE which is required by Jenkins so the installation process will fail after download. Would be nice to add a pre-installation step:

sudo apt-get install default-jre

Thanks for the tutorial. Very helpful.

One minor point … you may want to change the command:

echo deb http://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list

to:

echo deb https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list

as per the Jenkins instructions here:

https://pkg.jenkins.io/debian-stable/

(i.e. “http” becomes “https”.)

Hi, thanks for tutorial. I’ve executed all steps and installed jenkins on my droplet.

I am able to run jenkins via web link (www.mysite.bla:8081) and even do some actions - create a new job, look through configuration, etc. But after some time, jenkins becomes unavailable and I see notification: “Firefox can’t establish a connection to the server at mysiet.bla:8081.”

If I restart jenkins (sudo systemctl restart jenkins), it will be available for a short period of time and then problem will appear again.

I’m wondering if someone faced such kind of problem? What could be a cause of the issue? Currently, I’m trying to read jenkins’ logs, but I am new to jenkins and don’t understand much.

Thanks for the detailed tutorial but I’m having issue with step “Step 3 — Opening the Firewall”

sudo ufw allow 8080 Rules updated Rules updated (v6)

sudo ufw status Status: inactive

Please clarify what may be going wrong here ?

[UPDATE]

Per post https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-16-04

I ran command sudo ufw enable

**sudo ufw status Status: active

To Action From


8080 ALLOW Anywhere
8080 (v6) ALLOW Anywhere (v6) **

But as per your post I should have got

**To Action From


OpenSSH ALLOW Anywhere 8080 ALLOW Anywhere OpenSSH (v6) ALLOW Anywhere (v6) 8080 (v6) ALLOW Anywhere (v6)**

Please clarify how to get OpenSSH as well ?

Great GREAT Tutorial - thanks so much :)

After a time of activation, I cannot access my jenkins server through port 8080, although in systemctl it gives me ok and ufw also prints allow in port 8080

“Finally, we’ll install Jenkins and its dependencies, including Java”

That’s strange - after executing this line, jenkins failed to start and asked me to execute systemctl status jenkins.service to see what’s wrong. So I did and the result was ERROR: No Java executable found. So, it seems, Jenkins doesn’t install Java as dependency anymore? Which Java version should I install then? I’ve heard Jenkins might not be fully compatible with Java JDK 9, 10 or 11, but it was some time ago, so I’m not sure anymore.

This was very helpful. Thanks.

I think before you install jenkins you’ll also need to install appropriate version of JRE. There’s a guide available from DO here: installl JRE on ubuntu 16.04

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel