This article is written for those who were searching for a detailed and simple for the understanding guide on how to install Jenkins on Ubuntu Server.

Jenkins is a free and open-source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery.

In this guide, we will consider the case when you already have a server with the Ubuntu Server 18.04 LTS operating system installed on it.

You can read more about how to install Ubuntu Server 18.04 LTS in my guide «Installing Ubuntu Server 18.04 LTS».

In addition, 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 the server, you can use the command:

sudo apt-get install openssh-server

If you plan to connect to the server using the Windows operating system, you can use PuTTY, a freeware client for various remote access protocols, including SSH, Telnet, rlogin.

This guide covers connecting to a server using the iTerm2 terminal emulator installed on the macOS operating system.

Please note that you will need to open the following TCP ports to access your server:

  • 80 – to receive a free cryptographic certificate through the Let’s Encrypt certificate authority.
  • 443 – to access the Jenkins web interface.
  • 8080 – to access the Jenkins web interface.

Connect to the server on which it is planned to install Jenkins.

This guide discusses how to obtain a free cryptographic certificate through the Let’s Encrypt Certificate Authority. To receive and further update the free SSL certificate, we will use the Certbot software client, which is designed to simplify the receipt and renewal of the certificate through the Let’s Encrypt certificate authority.

Add the Certbot repository using the command:

sudo add-apt-repository ppa:certbot/certbot

Press the “Enter” button to confirm the addition of a new repository.

Now install the packages necessary for Jenkins to work using the command:

sudo apt-get install -y apache2 openjdk-11-jdk certbot python-certbot-apache

Please note that in this guide Apache will be used as the web server.

Please note that you can check the supported versions of Java by clicking on the link: https://jenkins.io/doc/administration/requirements/java/

Many programs written using Java use the “JAVA_HOME” environment variable to determine where to install Java. Therefore, you must define this variable and assign it a value that contains the path to the Java installation location.

Define the path to the Java installation location using the command:

sudo update-alternatives --config java

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

/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:

sudo vim /etc/environment

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.

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

Please note that the path to the Java installation location must be specified to the “bin” folder inclusively.

Now press the “Esc” button to exit the editing mode, and then enter “:x” and press the “Enter” button to save the changes and exit the editor.

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

source /etc/environment

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

echo $JAVA_HOME

Judging by the message received, the environment variable has the correct value.

Configure Apache for later work with the Jenkins control panel.

Enable the Apache web server module called “headers” with the command:

sudo a2enmod headers

Note that the headers module can be used to add more specific Cache-Control parameters.

Enable the Apache web server module called “proxy_http” using the command:

sudo a2enmod proxy_http

Please note that the “proxy_http” module acts as a proxy server for the HTTP and HTTPS protocols.

Enable the Apache web server module called “rewrite” with the command:

sudo a2enmod rewrite

Please note that the “rewrite” module is one of the most commonly used Apache web server modules and provides a flexible and powerful way to manipulate URLs.

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

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

In this manual, the jenkins.heyvaldemar.net subdomain will be used to access the Jenkins control panel from the Internet. You will need to specify your domain or subdomain by which your Jenkins will be accessible from the Internet.

Create the first virtual host file using a text editor using the command:

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

Press the “i” button to enter the editing mode, then insert the following configuration for the webserver to work:

In this manual, the jenkins.heyvaldemar.net subdomain will be used to access the Jenkins control panel from the Internet. You will need to specify your domain or subdomain by which your Jenkins will be accessible from the Internet.

Now press the “Esc” button to exit the editing mode, and then enter “:x” and press the “Enter” button to save the changes and exit the editor.

Create a second virtual host file using a text editor using the command:

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

Press the “i” button to enter the editing mode, then insert the following configuration for the webserver to work:

In this manual, the jenkins.heyvaldemar.net subdomain will be used to access the Jenkins control panel from the Internet. You will need to specify your domain or subdomain by which your Jenkins will be accessible from the Internet.

Now press the “Esc” button to exit the editing mode, and then enter “:x” and press the “Enter” button to save the changes and exit the editor.

Activate the first virtual host using the command:

sudo a2ensite jenkins.heyvaldemar.net.conf

Activate the second virtual host using the command:

sudo a2ensite jenkins.heyvaldemar.net-ssl.conf

Deactivate the default virtual host using the command:

sudo a2dissite 000-default.conf

Make sure that there are no errors in the syntax of the new Apache configuration file using the command:

sudo apache2ctl configtest

Restart Apache to apply the changes using the command:

sudo systemctl restart apache2

Verify that Apache started successfully using the command:

sudo systemctl status apache2

Now, to increase the security level of the webserver, it is necessary to obtain a cryptographic certificate for the domain or subdomain, through which the Jenkins will be accessible from the Internet.

To obtain and subsequently renew a free SSL certificate, we will use the Let’s Encrypt Certificate Authority, as well as the Certbot software client, which is designed to simplify the receipt and renewal of the certificate through the Let’s Encrypt Certificate Authority.

In this manual, the jenkins.heyvaldemar.net subdomain will be used to access the Jenkins control panel from the Internet. You will need to specify your domain or subdomain by which your Jenkins will be accessible from the Internet.

Request a cryptographic certificate using the command:

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

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

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

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

At the next stage, you need to choose: do you want to share the email address indicated above with the Electronic Frontier Foundation to receive newsletters.

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

The next step is to choose: do you want the parameters to automatically redirect HTTP traffic to HTTPS be automatically added to the Apache configuration file.

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

Please note that the cryptographic certificates received through the Let’s Encrypt Certificate Authority are valid for ninety days. Certbot automatically adds a script to renew the certificate in the task scheduler, and the script runs twice a day, automatically updating any cryptographic certificate that expires within thirty days.

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

sudo certbot renew --dry-run

Now add the official Jenkins key using the command:

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

Next, connect the Jenkins repository using the command:

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

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

sudo apt update

Now install Jenkins using the command:

sudo apt install -y jenkins

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

sudo vim /etc/default/jenkins

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

Now press the “Esc” button to exit the editing mode, and then enter “:x” and press the “Enter” button to save the changes and exit the editor.

Restart Jenkins to apply the changes using the command:

sudo systemctl restart jenkins

Check that Jenkins has started successfully using the command:

sudo systemctl status jenkins

Now you need to get the password that is required to unlock Jenkins. You can get the password using the command:

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

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

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

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

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

Now you can choose which plugins to install for Jenkins.

In this guide, we will cover the installation of the proposed plugins for Jenkins.

Click on the “Install suggested plugins” button.

The installation process for plugins has begun.

The next step is to specify: username, password name and email address to create a Jenkins administrator account.

Click on the “Save and Continue” button.

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

This guide 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 available from the Internet.

Click on the “Save and Finish” button.

Jenkins installation completed successfully.

Click on the “Start using Jenkins” button.

Everything is ready for use by Jenkins.

Author

Hi, I’m Vladimir Mikhalev, but my friends call me Valdemar. I have a lot of experience in the design and maintenance of various information systems. On my website, you will find detailed and clear guides for setting up IT solutions. Dive into the ocean, full of positive and technology! For cooperation: callvaldemar@gmail.com

Leave a Reply

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