How to install Jenkins on Ubuntu 18.04

s2 0

Jenkins
is an open source automation server that provides an easy way to set up a Continuous Integration and Continuous Delivery (CI / CD) pipeline.

Continuous Integration (CI) is a DevOps practice where team members regularly post their code changes to the version control repository, after which automated builds and tests are performed. Continuous Delivery (CD) is a series of practices that automatically create, test, and deploy code changes to production.

In this tutorial, we are going to show you how to install Jenkins on an Ubuntu 18.04 machine using the Jenkins Debian package repository.

Although this tutorial was written for Ubuntu 18.04 Bionic Beaver, the same steps can be used for Ubuntu 16.04 Xenial Xerus.

requirements

Before proceeding with this tutorial, make sure that you are logged in as a user with sudo permissions.

Install Jenkins

To install Jenkins on your Ubuntu system, do the following:

  1. Install Java.

    Since Jenkins is a Java application, the first step is to install Java. Update the package index and install the Java 8 OpenJDK package using the following commands:

    sudo apt updatesudo apt install openjdk-8-jdk

    The current version of Jenkins does not yet support Java 10 (and Java 11). If you have more than one version of Java installed on your computer, make sure that Java 8 is the default Java version.

  2. Add the Jenkins Debian repository.

    Import the Jenkins repository GPG keys as follows: wget
    Command:

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

    The above command should print OK This means that the key was imported successfully and packages from this repository are trusted.

    Next, add the Jenkins repository to the system with:

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

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

    sudo apt updatesudo apt install jenkins

    The Jenkins service will start automatically after the installation process is complete. You can check this by printing out 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 Wed 2018-08-22 13:03:08 PDT; 2min 16s ago
        Docs: man:systemd-sysv-generator(8)
        Tasks: 0 (limit: 2319)
    CGroup: /system.slice/jenkins.service

Adjust the firewall

If you are installing Jenkins on a remote Ubuntu server that is protected by a firewall, you will need to open the port 8080. Assuming you use UFW
To manage your firewall, you can open the port with the following command:

sudo ufw allow 8080

Confirm the change with:

sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
8080                       ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
8080 (v6)                  ALLOW       Anywhere (v6)

Set up Jenkins

To set up your new Jenkins installation, open your browser, enter your domain or IP address followed by port 8080, https://your_ip_or_domain:8080 and a screen similar to the following will appear:

During installation, the Jenkins installer creates an initial 32-character alphanumeric password. Use the following command to print out the password on your terminal:

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

Copy the password from your 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 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 asked to set up the first admin user. Fill in all the required information and click Save and Continue.

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

Confirm the URL by clicking the Save and Finish Button and the setup process will be completed.

click on the Start using Jenkins Button and you will be taken to the Jenkins dashboard logged in as the admin user you created in one of the previous steps.

At this point, you have successfully installed Jenkins on your system.

diploma

In this tutorial, you learned how to install and complete the initial configuration of Jenkins. You can now start exploring Jenkins features by checking out the official Jenkins documentation
Page.

If you have any questions please leave a comment below.