Jenkins Installation on Linux | Develop Software Efficiently

Tech specialists configuring Jenkins installation on Linux whilst instrucing what is jenkins used for

Our software development processes at IOFLOOD are greatly assisted with a properly configured Jenkins installation on Linux. This automated pipelines offers robust CI/CD automation features that we believe could also be of use to our bare metal hosting customers. This article delves into different installation methods for Jenkins on Linux, offering practical examples and techniques.

In this guide, we will navigate the process of install Jenkins on Ubuntu and other Linux distros. We will provide you with installation instructions for both APT and YUM. We will also delve into more advanced topics like compiling Jenkins from source and installing a specific version. Finally, we will guide you on how to use Jenkins and verify that the correct version is installed.

So, let’s dive in and begin installing Jenkins on your Linux system!

TL;DR: How Do I Install Jenkins on Linux?

You can install Jenkins on Ubuntu by first adding the Jenkins repository and its key, then using sudo apt-get install jenkins. For RPM-based systems like CentOS, run sudo yum install jenkins.

For example:

sudo apt update
sudo apt install openjdk-11-jdk
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install jenkins

This will install Jenkins on your Ubuntu system. However, this is just the basic way to install Jenkins on Linux. There’s much more to learn about installing Jenkins, including advanced installation methods, configurations, and troubleshooting common issues. Continue reading for a more detailed guide on how to install Jenkins on Linux.

Intro to Jenkins Installation on Linux

Jenkins is an open-source automation server that helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery. It’s a server-based system that runs in servlet containers such as Apache Tomcat.

Jenkins supports version control tools, including AccuRev, CVS, Subversion, Git, Mercurial, Perforce, ClearCase, and RTC, and can execute Apache Ant, Apache Maven, and sbt based projects as well as arbitrary shell scripts and Windows batch commands.

Let’s get started with the installation process. We’ll cover the installation using two popular package managers: apt and yum.

Install Jenkins on Ubuntu with APT

APT is the package manager for Ubuntu and similar systems. Here’s how you can install Jenkins using APT:

# Update the system
sudo apt update

# Install Java
sudo apt install openjdk-11-jdk

# Add the Jenkins Debian repository
wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

# Update the system again
sudo apt update

# Install Jenkins
sudo apt install jenkins

# Check Jenkins status
systemctl status jenkins

# Output:
# ● jenkins.service - LSB: Start Jenkins at boot time
#    Loaded: loaded (/etc/init.d/jenkins; generated)
#    Active: active (exited) since Tue 2022-03-01 10:33:37 PST; 2min 15s ago

This will install Jenkins and start it automatically. The systemctl status command is used to check the status of the Jenkins service. If it’s active, it means Jenkins is running successfully.

Install Jenkins on Linux with YUM

YUM is the package manager for Red Hat-based systems. Here’s how you can install Jenkins using YUM:

# Update the system
sudo yum update

# Install Java
sudo yum install java-1.8.0-openjdk-devel

# Add the Jenkins repository
sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key

# Install Jenkins
sudo yum install jenkins

# Start Jenkins
sudo systemctl start jenkins

# Enable Jenkins to start at boot
sudo systemctl enable jenkins

# Check Jenkins status
sudo systemctl status jenkins

# Output:
# ● jenkins.service - LSB: Jenkins Automation Server
#    Loaded: loaded (/etc/rc.d/init.d/jenkins; bad; vendor preset: disabled)
#    Active: active (running) since Tue 2022-03-01 10:33:37 PST; 2min 15s ago

This will install Jenkins and start it automatically. The systemctl status command is used to check the status of the Jenkins service. If it’s active, it means Jenkins is running successfully.

Install Jenkins from Source Code

For those who prefer to compile from source code, Jenkins provides that option. This method allows you to access the latest features and bug fixes immediately after they are committed to the repository.

# Clone the Jenkins repository

git clone https://github.com/jenkinsci/jenkins.git

# Switch to the directory

cd jenkins

# Compile the source code using Maven

mvn -B -DskipTests clean package

# Output:
# [INFO] BUILD SUCCESS

This will compile Jenkins and create a .war file in the target directory, which you can run using Java.

Installing Different Jenkins Versions

Different versions of Jenkins come with different features and bug fixes. Depending on your requirements, you might want to install a specific version of Jenkins.

Installing Specific Versions from Source

You can check out a specific version in the Jenkins repository and compile it.

# Check out a specific version

git checkout jenkins-2.263.4

# Compile the source code

mvn -B -DskipTests clean package

# Output:
# [INFO] BUILD SUCCESS

This will compile the specific version of Jenkins and create a .war file in the target directory.

Installing Specific Versions with APT and YUM

You can also install a specific version of Jenkins using APT or YUM.

# APT

sudo apt install jenkins=2.263.4

# YUM

sudo yum install jenkins-2.263.4

Jenkins Version Comparison

VersionKey ChangesCompatibility
2.263.4Security fixesJava 8, Java 11
2.277.1New password encryptionJava 11
2.289.1Update Center improvementsJava 11

Using Jenkins Installation on Linux

After installing Jenkins, you can access it at http://localhost:8080. The first time you access it, you’ll be asked to unlock Jenkins using the initial admin password.

# Display the initial admin password

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

# Output:
# 7d33ff5c543f4c4aae0891a7055e5b1e

You can then enter this password in the Jenkins setup wizard in your browser to unlock Jenkins and complete the setup.

To check the version of Jenkins you have installed, you can use the --version option.

# Check Jenkins version

java -jar /usr/share/jenkins/jenkins.war --version

# Output:
# Jenkins ver. 2.263.4

This will display the version of Jenkins that is currently installed.

Install Jenkins on Linux with Docker

Docker is a platform that simplifies software deployment using containerization. It allows you to package an application with all of its dependencies into a standardized unit for software development. Jenkins provides official Docker images that you can use.

# Pull the latest Jenkins Docker image

docker pull jenkins/jenkins:lts

# Run Jenkins in a Docker container

docker run -d -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts

# Output:
# 2d526e791a3a9f0a8006e5179bb77c3a3791f2b448fea6b7c288a6a8e3e4a211

This will download the latest Jenkins LTS Docker image and run it in a new Docker container. You can then access Jenkins at http://localhost:8080.

Install Jenkins on Linux with Kubernetes

Kubernetes is an open-source platform designed to automate deploying, scaling, and operating application containers. Jenkins provides a Helm chart that you can use to deploy Jenkins on Kubernetes.

# Add the Jenkins Helm repository

helm repo add jenkins https://charts.jenkins.io
helm repo update

# Install Jenkins

helm install my-jenkins jenkins/jenkins

# Output:
# NAME: my-jenkins
# LAST DEPLOYED: Tue Mar  1 15:37:31 2022
# NAMESPACE: default
# STATUS: deployed
# REVISION: 1
# NOTES:
# 1. Get your 'admin' user password by running:
#   printf $(kubectl get secret --namespace default my-jenkins -o jsonpath="{.data.jenkins-admin-password}" | base64 --decode);echo
# 2. Get the Jenkins URL to visit by running these commands in the same shell:
#   NOTE: It may take a few minutes for the LoadBalancer IP to be available.
#         You can watch the status of by running 'kubectl get svc --namespace default -w my-jenkins'
#   export SERVICE_IP=$(kubectl get svc --namespace default my-jenkins --template "{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}")
#   echo http://$SERVICE_IP:8080/login

This will deploy Jenkins on your Kubernetes cluster. You can then access Jenkins at the URL provided in the output.

Jenkins Installation Comparison

MethodComplexityFlexibilityUpdates
Package ManagerLowLowDepends on repository
Source CodeHighHighImmediate
DockerMediumMediumDepends on image
KubernetesHighHighDepends on chart

Each installation method has its advantages and disadvantages. While installing from a package manager or Docker might be easier, compiling from source or deploying on Kubernetes offers more flexibility. The best method depends on your specific needs and environment.

Solving Issues: Jenkins Install

Even with the best of guides, you might encounter issues when installing Jenkins on Linux. Let’s discuss some common problems and their solutions.

Jenkins Service Fails to Start

After installation, you might find that the Jenkins service fails to start. This is often due to insufficient memory. Jenkins requires at least 256 MB of memory to run.

# Check system memory
free -m

# Output:
#               total        used        free      shared  buff/cache   available
# Mem:           1990         380         130          19        1479        1440
# Swap:          2047           0        2047

The free -m command displays the total, used, and free memory in MB. If you have less than 256 MB of free memory, you might need to increase your system’s memory.

Jenkins Web Interface is Unavailable

After starting the Jenkins service, you might find that the web interface is not available at http://localhost:8080. This could be due to a firewall blocking the port.

# Check if port 8080 is open
sudo ufw status

# Output:
# Status: active
#
# To                         Action      From
# --                         ------      ----
# 8080                       ALLOW       Anywhere
# 8080 (v6)                  ALLOW       Anywhere (v6)

The sudo ufw status command displays the status of the firewall. If port 8080 is not allowed, you can open it using the sudo ufw allow 8080 command.

Jenkins is Slow or Unresponsive

If Jenkins is slow or unresponsive, it could be due to a large number of builds or jobs. You can manage this by setting up job retention policies in the Jenkins settings.

# Display number of builds
ls /var/lib/jenkins/jobs/*/builds | wc -l

# Output:
# 500

The ls /var/lib/jenkins/jobs/*/builds | wc -l command displays the number of builds. If this number is large, consider setting up job retention policies.

Remember, troubleshooting is a normal part of any software installation process. Don’t be discouraged if you encounter issues. With persistence and the right resources, you’ll have Jenkins up and running on your Linux system in no time.

Core Concepts of CI/CD

Jenkins, an open-source automation server, has revolutionized the software development landscape. It’s not just a tool; it’s a complete ecosystem for Continuous Integration (CI) and Continuous Delivery (CD). But what does that mean?

Understanding Continuous Integration (CI)

Continuous Integration is a development practice that requires developers to integrate code into a shared repository several times a day. Each check-in is then verified by an automated build, allowing teams to detect problems early.

# Example of a developer pushing changes to a shared repository

git add .
git commit -m "Integrate new feature"
git push origin main

# Output:
# [main 9a377c6] Integrate new feature
#  1 file changed, 1 insertion(+), 1 deletion(-)
# Counting objects: 3, done.
# Delta compression using up to 8 threads.
# Compressing objects: 100% (3/3), done.
# Writing objects: 100% (3/3), 352 bytes | 352.00 KiB/s, done.
# Total 3 (delta 2), reused 0 (delta 0)
# remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
# To github.com:username/repo.git
#    1a2b3c4..5d6e7f8  main -> main

In the above example, a developer makes changes to the code, commits those changes, and pushes them to a shared repository. Jenkins can then pull this code and build it, ensuring the changes integrate correctly with the existing codebase.

Grasping Continuous Delivery (CD)

Continuous Delivery is an extension of continuous integration to make sure that you can release new changes to your customers quickly in a sustainable way. This means that on top of having automated your testing, you also have automated your release process and you can deploy your application at any point of time by clicking on a button.

# Example of Jenkins automating the deployment process

echo "Deploying application..."

# Output:
# Deploying application...

In this simplified example, Jenkins automates the deployment process, allowing you to deploy your application at any time.

What is Jenkins Used For?

Jenkins is more than just a tool; it’s a critical player in the DevOps landscape. It can automate various stages of your delivery pipeline and is used in conjunction with other tools to form a complete CI/CD pipeline, facilitating DevOps practices.

Jenkins Pipelines: Streamlining CI/CD

Jenkins Pipelines are a suite of plugins that support implementing and integrating continuous delivery pipelines into Jenkins. A pipeline has an extensible automation server for creating simple or complex delivery pipelines “as code” via pipeline DSL (Domain-specific Language).

# Example of a Jenkins Pipeline script

pipeline {
    agent any

    stages {
        stage('Build') {
            steps {
                echo 'Building..'
            }
        }
        stage('Test') {
            steps {
                echo 'Testing..'
            }
        }
        stage('Deploy') {
            steps {
                echo 'Deploying....'
            }
        }
    }
}

# Output:
# [Pipeline] echo
# Building..
# [Pipeline] echo
# Testing..
# [Pipeline] echo
# Deploying....

In this example, a Jenkins Pipeline script defines three stages: Build, Test, and Deploy. Jenkins will execute these stages in order, providing a streamlined CI/CD pipeline.

Jenkins Plugins: Enhancing Functionality

Jenkins’ functionality can be extended with plugins. There are over a thousand plugins available for Jenkins to integrate with various platforms and tools.

# Example of installing a Jenkins plugin

echo "Installing Git plugin..."

# Output:
# Installing Git plugin...

In this simplified example, a Jenkins plugin (Git plugin in this case) is installed, allowing Jenkins to integrate with Git.

Further Resources for Jenkins Mastery

Want to dive deeper into Jenkins? Here are some resources to help you on your journey:

  1. Official Jenkins Documentation: The official documentation provides comprehensive information on various topics, from how to install jenkins on ubuntu to plugins and pipelines.

  2. Definitive Jenkins Installation on Linux Guide: Provides a detailed guide on what is Jenkins used for continuous integration on a project.

  3. How to Install Jenkins in Linux Interactive Course: Covers the basics of Jenkins and how to install Jenkins in Linux.

Recap: Jenkins Installation on Linux

In this comprehensive guide, we’ve delved into the process of installing Jenkins on Linux, an essential step in setting up a robust CI/CD pipeline. Jenkins, as we’ve seen, is a powerful automation server that orchestrates your software build, test, and deployment tasks, making it an invaluable tool in the DevOps landscape.

We started with the basics, guiding you through a step-by-step process of installing Jenkins on Linux for beginners. We then moved on to more advanced topics, discussing how to compile Jenkins from source, install specific versions, and verify the installed version. We also explored alternative approaches to installing Jenkins, such as using Docker or Kubernetes, each with its own advantages and disadvantages.

We addressed common issues you might encounter during installation and provided solutions to help you troubleshoot effectively. Throughout the guide, we provided practical examples to help you understand the concepts better and get hands-on experience.

Here’s a quick comparison of the methods we’ve discussed:

MethodComplexityFlexibilityUpdates
Package ManagerLowLowDepends on repository
Source CodeHighHighImmediate
DockerMediumMediumDepends on image
KubernetesHighHighDepends on chart

Whether you’re a beginner just starting out with Jenkins or an experienced developer looking to brush up your skills, we hope this guide has provided you with a deeper understanding of the installation process and its nuances.

The ability to install and configure Jenkins effectively is a crucial skill in today’s DevOps-oriented industry. With this guide, you’re now equipped to take on this task confidently. Happy coding!