2123 words
11 minutes

Install Jenkins on Ubuntu Server

This article is for those looking for a detailed and straightforward guide on installing Jenkins on Ubuntu Server.

Jenkins is an open-source Java software system designed to provide a continuous software integration process.

IMPORTANT

OpenSSH must be installed on the server, and port 22 must be open in order to be able to connect to the server using the SSH protocol.

To install OpenSSH on a server, you can use the command:

Terminal window
sudo apt install openssh-server
NOTE

To connect to the server from a Windows system, you can use tools like PuTTY or MobaXterm.

NOTE

This guide walks you through connecting to a server with the iTerm2 terminal emulator on macOS.

CAUTION

You will need to open the following TCP ports for access to the services:

  • TCP port 80 - to receive a free cryptographic certificate through the Let’s Encrypt CA.
  • TCP port 443 - to access Jenkins web interface.

We connect to the server on which you plan to install Jenkins.

NOTE

To obtain and subsequently renew a free SSL certificate, we will use the Let’s Encrypt certification authority, as well as the Certbot software client, which is designed to make it as easy as possible to obtain and renew a certificate through the Let’s Encrypt certification authority.

Update the local package index to the latest changes in the repositories using the command:

Terminal window
sudo apt update

Install Jenkins on Ubuntu Server - Step 1

Now we will install the packages required for Jenkins to work using the command:

Terminal window
sudo apt install -y apache2 apt-transport-https certbot python3-certbot-apache openjdk-11-jdk
NOTE

Supported Java versions can be found in the Jenkins documentation on the requirements page.

Install Jenkins on Ubuntu Server - Step 2

Many programs written using Java use the “JAVA_HOME” environment variable to determine where Java is installed. Therefore, you need to define this variable and assign it a value containing the path to the Java installation location.

Let’s define the path to the Java installation location using the command:

Terminal window
sudo update-alternatives --config java

Install Jenkins on Ubuntu Server - Step 3

In this example, the path to the Java installation location looks like this:

Terminal window
/usr/lib/jvm/java-11-openjdk-amd64/bin/

In order to define an environment variable and assign a value to it, you need to make changes to the “environment” file by opening it in a text editor using the command:

Terminal window
sudo vim /etc/environment

Install Jenkins on Ubuntu Server - Step 4

Press the “i” button to switch to edit mode, then at the end of the file define a new variable “JAVA_HOME” and assign it a value containing the path to the Java installation location obtained earlier.

Terminal window
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64/bin/"
NOTE

The path to the Java installation location must be specified up to and including the “bin” folder.

Install Jenkins on Ubuntu Server - Step 5

Now press the “Esc” button to exit edit mode, and then type "" and press the “Enter” button to save your changes and exit the editor.

Install Jenkins on Ubuntu Server - Step 6

Next, you need to apply the changes made to the current session using the command:

Terminal window
source /etc/environment

Install Jenkins on Ubuntu Server - Step 7

Now let’s make sure that the environment variable has the correct value using the command:

Terminal window
echo $JAVA_HOME

Install Jenkins on Ubuntu Server - Step 8

Based on the message received, the environment variable has the correct value.

Let’s configure Apache for further work with the Jenkins dashboard.

We enable the Apache webserver module called “headers” using the command:

Terminal window
sudo a2enmod headers
NOTE

The “headers” module can be used to add more specific “Cache-Control” parameters.

Install Jenkins on Ubuntu Server - Step 9

We enable the Apache webserver module called “proxy_http” using the command:

Terminal window
sudo a2enmod proxy_http
NOTE

The “proxy_http” module acts like a proxy server for the HTTP and HTTPS protocols.

Install Jenkins on Ubuntu Server - Step 10

We enable the Apache webserver module called “rewrite” using the command:

Terminal window
sudo a2enmod rewrite
NOTE

The “rewrite” module is one of the most commonly used modules in the Apache webserver and provides a flexible and powerful way to manipulate URLs.

Install Jenkins on Ubuntu Server - Step 11

Now you need to create two virtual host files (called a block in Nginx), which Jenkins will work with in the future.

Two virtual host files will be required to provide access to Jenkins over HTTPS, as well as to enable Jenkins to be used at https://jenkins.heyvaldemar.net, without specifying port 8080 in the browser address bar.

NOTE

In this tutorial, you will use the jenkins.heyvaldemar.net subdomain to access Jenkins from the Internet. You will need to specify your domain or subdomain by which your Jenkins will be accessible from the Internet.

Let’s create the first virtual host file using a text editor using the command:

Terminal window
sudo vim /etc/apache2/sites-available/jenkins.heyvaldemar.net.conf

Install Jenkins on Ubuntu Server - Step 12

Hit the “i” button to go into edit mode, then insert the following configuration for the webserver to work.

NOTE

In this tutorial, you will use the jenkins.heyvaldemar.net subdomain to access Jenkins from the Internet. You will need to specify your domain or subdomain by which your Jenkins will be accessible from the Internet.

Install Jenkins on Ubuntu Server - Step 13

Now press the “Esc” button to exit edit mode, and then type "" and press the “Enter” button to save your changes and exit the editor. Install Jenkins on Ubuntu Server - Step 14

Let’s create a second virtual host file using a text editor using the command:

Terminal window
sudo vim /etc/apache2/sites-available/jenkins.heyvaldemar.net-ssl.conf

Install Jenkins on Ubuntu Server - Step 15

Hit the “i” button to go into edit mode, then insert the following configuration for the webserver to work.

NOTE

In this tutorial, you will use the jenkins.heyvaldemar.net subdomain to access Jenkins from the Internet. You will need to specify your domain or subdomain by which your Jenkins will be accessible from the Internet.

Install Jenkins on Ubuntu Server - Step 16

Now press the “Esc” button to exit edit mode, and then type "" and press the “Enter” button to save your changes and exit the editor.

Install Jenkins on Ubuntu Server - Step 17

We activate the first virtual host using the command:

Terminal window
sudo a2ensite jenkins.heyvaldemar.net.conf

Install Jenkins on Ubuntu Server - Step 18

We activate the second virtual host using the command:

Terminal window
sudo a2ensite jenkins.heyvaldemar.net-ssl.conf

Install Jenkins on Ubuntu Server - Step 19

Deactivate the default virtual host using the command:

Terminal window
sudo a2dissite 000-default.conf

Install Jenkins on Ubuntu Server - Step 20

Verify that there are no errors in the syntax of the new Apache config file using the command:

Terminal window
sudo apache2ctl configtest

Install Jenkins on Ubuntu Server - Step 21

Restart Apache to apply the changes, using the command:

Terminal window
sudo systemctl restart apache2

Install Jenkins on Ubuntu Server - Step 22

Let’s check that Apache has started successfully using the command:

Terminal window
sudo systemctl status apache2

Install Jenkins on Ubuntu Server - Step 23

Now, in order to increase the security level of the webserver, you need to obtain a cryptographic certificate for the domain or subdomain, through which the Jenkins dashboard will be accessible from the Internet.

NOTE

To obtain and subsequently renew a free SSL certificate, we will use the Let’s Encrypt certification authority, as well as the Certbot software client, which is designed to make it as easy as possible to obtain and renew a certificate through the Let’s Encrypt certification authority.

NOTE

In this tutorial, you will use the jenkins.heyvaldemar.net subdomain to access Jenkins from the Internet. You will need to specify your domain or subdomain by which your Jenkins will be accessible from the Internet.

Let’s request a cryptographic certificate using the command:

Terminal window
sudo certbot --apache -d jenkins.heyvaldemar.net

Install Jenkins on Ubuntu Server - Step 24

Next, we specify the email address to which Let’s Encrypt will send notifications about the expiration of the cryptographic certificate and press the “Enter” button.

Install Jenkins on Ubuntu Server - Step 25

The next step is to read and accept the terms of use of the services provided.

Press the button “a”, then “Enter”, if you agree with the terms of use of the services provided.

Install Jenkins on Ubuntu Server - Step 26

The next step is to choose: do you want to share the above email address with the Electronic Frontier Foundation in order to receive newsletters.

Press the “n” button, then “Enter”.

Install Jenkins on Ubuntu Server - Step 27

At the next stage, you need to choose: do you want the parameters to be automatically added to the Apache configuration file for automatically redirecting HTTP traffic to HTTPS.

Press the button “2”, then “Enter”.

Install Jenkins on Ubuntu Server - Step 28

NOTE

Cryptographic certificates obtained through Let’s Encrypt CA are valid for ninety days. Certbot automatically adds a script to renew the certificate to the task scheduler, and the script runs twice a day, automatically renewing any cryptographic certificate that expires within thirty days.

You can check the functionality of the cryptographic certificate renewal process using the command:

Terminal window
sudo certbot renew --dry-run

Install Jenkins on Ubuntu Server - Step 29

Now let’s add the official Jenkins key using the command:

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

Install Jenkins on Ubuntu Server - Step 30

Next, we connect the Jenkins repository using the command:

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

Install Jenkins on Ubuntu Server - Step 31

Update the local package index to the latest changes in the repositories using the command:

Terminal window
sudo apt update

Install Jenkins on Ubuntu Server - Step 32

Now let’s install Jenkins using the command:

Terminal window
sudo apt install -y jenkins

Install Jenkins on Ubuntu Server - Step 33

Now you need to make changes to the Jenkins configuration file by opening it in a text editor using the command:

Terminal window
sudo vim /etc/default/jenkins

Install Jenkins on Ubuntu Server - Step 34

Hit the “i” button to enter edit mode, find the line JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT" and add the parameter --httpListenAddress=127.0.0.1.

Install Jenkins on Ubuntu Server - Step 35

Now press the “Esc” button to exit edit mode, and then type "" and press the “Enter” button to save your changes and exit the editor.

Install Jenkins on Ubuntu Server - Step 36

Restart Jenkins to apply the changes made using the command:

Terminal window
sudo systemctl restart jenkins

Install Jenkins on Ubuntu Server - Step 37

Let’s check that Jenkins has started successfully using the command:

Terminal window
sudo systemctl status jenkins

Install Jenkins on Ubuntu Server - Step 38

Now you need to get the password that you need to unlock Jenkins.

You can get the password using the command:

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

Install Jenkins on Ubuntu Server - Step 39

Save the resulting password as you will need it in the next step.

To continue the Jenkins installation process, you need to go from the workstation to the link https://jenkins.heyvaldemar.net, where jenkins.heyvaldemar.net is the name of my server. Accordingly, you need to provide the name or IP address of your Jenkins server.

Next, you need to provide a password to unlock Jenkins.

In the “Administrator password” field, specify the previously received password to unlock Jenkins and click on the “Continue” button.

Install Jenkins on Ubuntu Server - Step 40

Now you can choose which plugins to install for Jenkins.

NOTE

In this tutorial, we will be looking at installing the suggested plugins for Jenkins.

Click on the “Install suggested plugins” button.

Install Jenkins on Ubuntu Server - Step 41

The process of installing plugins has begun.

Install Jenkins on Ubuntu Server - Step 42

At the next step, you need to specify: login, password, name, and email address to create a Jenkins administrator account.

Click on the “Save and Continue” button.

Install Jenkins on Ubuntu Server - Step 43

In the “Jenkins URL” field, specify the domain or subdomain by which your Jenkins is accessible from the Internet.

NOTE

This tutorial will use the jenkins.heyvaldemar.net subdomain to access Jenkins from the Internet. You will need to specify your domain or subdomain by which your Jenkins will be accessible from the Internet.

Click on the “Save and Finish” button.

Install Jenkins on Ubuntu Server - Step 44

Jenkins installation completed successfully.

Click on the “Start using Jenkins” button.

Install Jenkins on Ubuntu Server - Step 45

Everything is ready to use Jenkins.

Install Jenkins on Ubuntu Server - Step 46


Social Channels#


Community of IT Experts#


Is this content AI-generated?

No. Every article on this blog is written by me personally, drawing on decades of hands-on IT experience and a genuine passion for technology.

I use AI tools exclusively to help polish grammar and ensure my technical guidance is as clear as possible. However, the core ideas, strategic insights, and step-by-step solutions are entirely my own, born from real-world work.

Because of this human-and-AI partnership, some detection tools might flag this content. You can be confident, though, that the expertise is authentic. My goal is to share road-tested knowledge you can trust.

Install Jenkins on Ubuntu Server
https://www.heyvaldemar.com/install-jenkins-on-ubuntu-server/
Author
Vladimir Mikhalev
Published at
2021-04-10
License
CC BY-NC-SA 4.0