Your Jenkins Journey Starts Here: A Quick and Easy Setup Guide

Divakar ChakaliDivakar Chakali
4 min read

Here's a straightforward guide on how to set up Jenkins on different Linux distributions. The process generally involves adding the Jenkins repository, importing its GPG key, and then installing the package using your distribution's package manager.


Prerequisites

Before you start, make sure your Linux machine has the following:

  • Java Development Kit (JDK) 17 or 21: Jenkins requires a Java Runtime Environment (JRE) to run. As of recent updates, Java 17 and Java 21 are the recommended versions. Support for older versions like Java 11 has been deprecated.
  • Sufficient Resources: A minimum of 256 MB of RAM (512 MB recommended) and 1 GB of disk space (10 GB recommended for Docker images, logs, etc.).

Ubuntu/Debian

This is the most common method for Debian-based systems.

  1. Update your package list and install Java:

    sudo apt update
    sudo apt install openjdk-17-jdk
    

    This command updates your package list and installs OpenJDK 17, a stable and supported version for Jenkins.

  2. Add the Jenkins repository key:

    curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
    

    This command downloads and imports the GPG key, which is used to verify the authenticity of the Jenkins package.

  3. Add the Jenkins repository to your system's sources:

    echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
    

    This adds the official Jenkins repository to your system, so apt knows where to download the Jenkins package from.

  4. Update your package list and install Jenkins:

    sudo apt update
    sudo apt install jenkins
    

    This command installs the Jenkins service and its dependencies.

  5. Start and enable the Jenkins service:

    sudo systemctl start jenkins
    sudo systemctl enable jenkins
    

    These commands start the service and configure it to automatically start on boot.


CentOS/RHEL/Fedora

This method uses the yum or dnf package manager for Red Hat-based systems.

  1. Install Java and wget: First, install the necessary OpenJDK package. Then, check for wget, which is a command-line tool used to download files. If you get a "command not found" error, use the appropriate command to install it.

    sudo yum install java-17-openjdk # For CentOS/RHEL
    sudo dnf install java-17-openjdk # For Fedora
    
    sudo yum install wget -y # For CentOS/RHEL
    sudo dnf install wget -y # For Fedora
    
  2. Add the Jenkins repository:

    sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
    

    This downloads the repository file for Jenkins.

  3. Import the repository key:

    sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
    

    This command imports the GPG key to ensure the package's integrity.

  4. Install Jenkins:

    sudo yum install jenkins # For CentOS/RHEL
    sudo dnf install jenkins # For Fedora
    

    This installs Jenkins.

  5. Start and enable the Jenkins service:

    sudo systemctl start jenkins
    sudo systemctl enable jenkins
    

    These commands start the Jenkins service and ensure it runs on system startup.


Best Practice: Configure a Persistent /tmp Directory

This is an optional but highly recommended step to avoid common Jenkins build failures related to the temporary directory. By default, some Linux systems use a RAM-based /tmp that can be too small or non-executable, causing build processes to fail. These steps create a dedicated, persistent, disk-backed /tmp directory.

  1. Create a new, persistent temporary directory:

    sudo mkdir -p /var/tmp_disk
    sudo chmod 1777 /var/tmp_disk
    

    This creates a new directory and sets its permissions to allow all users to read, write, and execute files, but only delete files they own (a standard permission for shared temporary directories).

  2. Mount the new directory over the existing /tmp:

    sudo mount --bind /var/tmp_disk /tmp
    

    This command "bind mounts" the new directory (/var/tmp_disk) over /tmp, so all temporary files will now be written to a persistent, disk-backed location.

  3. Make the change permanent:

    echo '/var/tmp_disk /tmp none bind 0 0' | sudo tee -a /etc/fstab
    

    This command adds an entry to the /etc/fstab file, ensuring the bind mount is automatically re-established every time the system reboots.

  4. Prevent the system from managing the old tmp mount:

    sudo systemctl mask tmp.mount
    

    This command masks the default tmp.mount service, preventing it from interfering with your new configuration.

  5. Verify the change:

    df -h /tmp
    

    This command will show the new mount point, confirming that /tmp is now a persistent, disk-backed location.


Initial Setup

After installation, the setup process is the same for all distributions.

  1. Access Jenkins: Open your web browser and navigate to http://<your_server_ip_or_domain>:8080. The default port for Jenkins is 8080.

  2. Unlock Jenkins: The first time you access Jenkins, it will ask for an initial administrator password. To get this password, run the following command on your server:

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

    Copy the password and paste it into the Jenkins setup wizard.

  3. Install Plugins: You'll be prompted to install plugins. It's recommended to select "Install suggested plugins," as this will set up Jenkins with the most common and useful plugins for a typical CI/CD workflow.

  4. Create Admin User: After the plugins are installed, you'll be asked to create a first admin user. Fill in the details to complete the setup.

  5. Start Building: Once the setup is complete, you will be taken to the Jenkins dashboard, ready to start creating your first build job.

0
Subscribe to my newsletter

Read articles from Divakar Chakali directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Divakar Chakali
Divakar Chakali