How to Install Jenkins on Ubuntu 20.04

Posted 

4 min read

Jenkins is an open-source automation server that can be used to easily set up continuous integration and continuous delivery (CI/CD) pipelines.

Continuous integration (CI) is a DevOps practice in which team members regularly commit their code changes to the version control repository, after which automated builds and tests are run. Continuous delivery (CD) is a series of practices where code changes are automatically built, tested, and deployed to production.

Jenkins can be installed as a standalone application, as a servlet in a Java servlet container such as Apache Tomcat or can be run as a Docker container.

This article explains how to install Jenkins on Ubuntu 20.04 as a standalone service.

Installing Java

Jenkins is a Java application and requires Java 8 or later to be installed on the system. We’ll install OpenJDK 11 , the open-source implementation of the Java Platform.

Run the following commands as root or user with sudo privileges or root to install OpenJDK 11:

sudo apt updatesudo apt install openjdk-11-jdk

Once the installation is complete, verify it by checking the Java version:

java -version

The output should look something like this:

openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

Installing Jenkins

Installing Jenkins on Ubuntu is relatively straightforward. We’ll enable the Jenkins APT repository, import the repository GPG key, and install the Jenkins package.

Import the GPG keys of the Jenkins repository using the following wget command:

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

Next, add the Jenkins repository to the system with:

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

Once the Jenkins repository is enabled, update the apt package list and install the latest version of Jenkins by typing:

sudo apt updatesudo apt install jenkins

If you get an error message saying:

Error: W: GPG error: https://pkg.jenkins.io/debian-stable binary/ Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY 9B7D32F2D50582E6"

Import the key with:

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 9B7D32F2D50582E6

Jenkins service will automatically start after the installation process is complete. You can verify it by printing the service status:

systemctl status jenkins

You should see something like this:

● jenkins.service - LSB: Start Jenkins at boot time
     Loaded: loaded (/etc/init.d/jenkins; generated)
     Active: active (exited) since Thu 2020-07-16 20:22:12 UTC; 15min ago
...

Adjusting Firewall

If you are installing Jenkins on a remote Ubuntu server that is protected by a firewall , you’ll need to open port 8080.

Typically, you would want to allow access to the Jenkins server only from a specific IP address or IP range. For example, to allow connections only from the “192.168.121.0/24” subnet, you would run the following command:

sudo ufw allow proto tcp from 192.168.121.0/24 to any port 8080

If you need to allow access from anywhere run:

sudo ufw allow 8080

Setting Up Jenkins

To set up your new Jenkins installation, open your browser, type your domain or IP address followed by port 8080, http://your_ip_or_domain:8080.

A page similar to the following will be displayed, prompting you to enter the Administrator password that is created during the installation:

Use cat to display the password on the terminal:

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

You should see a 32-character long alphanumeric password, as shown below:

06cbf25d811a424bb236c76fd6e04c47

Copy the password from the terminal, paste it into the “Administrator password” field and click “Continue”.

On the next screen, the setup wizard will ask you whether you want to install suggested plugins or you want to select specific plugins.

Click on the “Install suggested plugins” box and the installation process will start immediately.

Once the plugins are installed, you will be prompted to set up the first admin user. Fill out all required information and click “Save and Continue”.

The next page will ask you to set the URL for your Jenkins instance. The field will be populated with an automatically generated URL.

Confirm the URL by clicking on the Save and Finish button, and the setup process will be completed.

Click on the Start using Jenkins button, and you will be redirected to the Jenkins dashboard logged in as the admin user you have created in one of the previous steps.

At this point, you’ve successfully installed Jenkins on your server.

Conclusion

In this tutorial, we have shown you how to install and complete the initial configuration of Jenkins on Ubuntu systems.

You can now visit the official Jenkins documentation page and start exploring Jenkins’s workflow and plug-in model.

If you have any questions, please leave a comment below.