BLOG POSTS
How to Install Jenkins on Ubuntu 24

How to Install Jenkins on Ubuntu 24

Jenkins is a powerful open-source automation server that’s become the backbone of CI/CD pipelines for development teams worldwide. Installing Jenkins on Ubuntu 24 gives you a robust foundation for automating builds, tests, and deployments across your entire software development lifecycle. This guide walks you through the complete installation process, from system preparation to securing your Jenkins instance, plus troubleshooting the most common issues you’ll encounter along the way.

How Jenkins Works

Jenkins operates as a web-based automation server that continuously monitors your version control repositories for changes. When it detects updates, it automatically triggers predefined jobs that can compile code, run tests, generate reports, and deploy applications. The magic happens through Jenkins’ plugin ecosystem – over 1,800 plugins that integrate with practically every tool in your development stack.

The architecture is straightforward: Jenkins runs as a Java application on your server, exposing a web interface on port 8080 by default. It maintains a job queue, manages build agents (nodes), and stores all configuration data in its home directory. For teams running multiple projects, Jenkins can distribute workloads across multiple nodes, making it incredibly scalable.

Prerequisites and System Requirements

Before diving into installation, let’s ensure your Ubuntu 24 system meets the requirements. Jenkins needs Java to run, and while it supports both OpenJDK and Oracle JDK, OpenJDK 11 or 17 works perfectly for most setups.

Component Minimum Recommended
RAM 256 MB 4 GB+
Disk Space 1 GB 50 GB+
Java Version OpenJDK 11 OpenJDK 17
CPU 1 core 4+ cores

First, update your system and install Java:

sudo apt update && sudo apt upgrade -y
sudo apt install openjdk-17-jdk -y
java -version

You should see output confirming Java 17 installation. If you’re running on a VPS with limited resources, OpenJDK 11 will work fine and uses slightly less memory.

Step-by-Step Jenkins Installation

Method 1: Official Jenkins Repository (Recommended)

The most reliable way to install Jenkins is through the official Jenkins repository. This ensures you get the latest stable version with proper package management:

# Add 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

# Add Jenkins repository to sources list
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

# Update package index
sudo apt update

# Install Jenkins
sudo apt install jenkins -y

The installation automatically creates a Jenkins user, sets up the service, and configures basic security settings. Jenkins will start automatically after installation.

Method 2: WAR File Installation

For development environments or when you need more control over the installation directory:

# Download Jenkins WAR file
wget https://get.jenkins.io/war-stable/latest/jenkins.war

# Create Jenkins directory
sudo mkdir -p /opt/jenkins
sudo mv jenkins.war /opt/jenkins/

# Run Jenkins
cd /opt/jenkins
java -jar jenkins.war --httpPort=8080

This method gives you flexibility but requires manual service configuration for production use.

Initial Jenkins Configuration

After installation, start and enable the Jenkins service:

sudo systemctl start jenkins
sudo systemctl enable jenkins
sudo systemctl status jenkins

The status command should show Jenkins as active and running. Now access Jenkins through your web browser at http://your-server-ip:8080. You’ll encounter the initial setup wizard.

Retrieve the initial admin password:

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

Copy this password and paste it into the web interface. The setup wizard will guide you through:

  • Installing suggested plugins (recommended for most users)
  • Creating your first admin user
  • Configuring the Jenkins URL
  • Completing the initial setup

The plugin installation takes 5-10 minutes depending on your internet connection. These plugins include Git integration, build tools, and essential utilities you’ll need for most CI/CD workflows.

Security Configuration and Best Practices

Jenkins security deserves special attention since it often has access to your entire codebase and deployment infrastructure. Here’s how to lock it down properly:

Firewall Configuration

# Enable UFW firewall
sudo ufw enable

# Allow SSH (important - don't lock yourself out!)
sudo ufw allow ssh

# Allow Jenkins port
sudo ufw allow 8080/tcp

# Check firewall status
sudo ufw status

Reverse Proxy Setup with Nginx

Running Jenkins behind a reverse proxy improves security and allows HTTPS termination:

# Install Nginx
sudo apt install nginx -y

# Create Jenkins virtual host
sudo nano /etc/nginx/sites-available/jenkins

Add this configuration:

upstream jenkins {
    keepalive 32;
    server 127.0.0.1:8080;
}

server {
    listen 80;
    server_name your-domain.com;
    
    location / {
        proxy_pass http://jenkins;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_connect_timeout 90;
        proxy_send_timeout 90;
        proxy_read_timeout 90;
        proxy_buffering off;
        proxy_request_buffering off;
    }
}

Enable the site and restart Nginx:

sudo ln -s /etc/nginx/sites-available/jenkins /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

Common Issues and Troubleshooting

Even with careful installation, you might encounter some common issues. Here are the most frequent problems and their solutions:

Port 8080 Already in Use

If another service is using port 8080, change Jenkins’ port:

# Edit Jenkins configuration
sudo nano /etc/default/jenkins

# Find and modify the HTTP_PORT line
HTTP_PORT=8081

# Restart Jenkins
sudo systemctl restart jenkins

Java Version Conflicts

Jenkins might fail to start if multiple Java versions are installed:

# Check current Java version
java -version

# List installed Java versions
sudo update-alternatives --list java

# Set default Java version
sudo update-alternatives --config java

Permission Issues

The Jenkins user needs proper permissions for workspace operations:

# Fix Jenkins home directory permissions
sudo chown -R jenkins:jenkins /var/lib/jenkins

# Add Jenkins user to required groups
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins

Memory Issues on Low-Spec Servers

For smaller VPS instances, you might need to limit Jenkins memory usage:

# Edit Jenkins service configuration
sudo nano /etc/systemd/system/jenkins.service.d/override.conf

# Add memory limits
[Service]
Environment="JAVA_OPTS=-Xmx1024m -XX:MaxMetaspaceSize=256m"

# Reload and restart
sudo systemctl daemon-reload
sudo systemctl restart jenkins

Performance Optimization

Jenkins performance depends heavily on proper configuration. Here are key optimizations that make a real difference in production environments:

Optimization Impact Implementation Difficulty
SSD Storage High Hardware change
Build Agent Distribution Very High Medium
Plugin Cleanup Medium Easy
Workspace Cleanup Medium Easy
JVM Tuning High Hard

JVM Performance Tuning

For production deployments, especially on Dedicated Servers, proper JVM tuning is crucial:

# Edit Jenkins service file
sudo systemctl edit jenkins

# Add JVM optimizations
[Service]
Environment="JAVA_OPTS=-server -Xms2g -Xmx4g -XX:+UseG1GC -XX:+UseStringDeduplication -XX:+DisableExplicitGC -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap"

Real-World Use Cases and Examples

Jenkins shines in various scenarios. Here are some practical examples of how teams use Jenkins effectively:

Basic CI Pipeline for Web Applications

A typical pipeline for a Node.js application might include:

pipeline {
    agent any
    
    stages {
        stage('Checkout') {
            steps {
                git branch: 'main', url: 'https://github.com/your-org/your-app.git'
            }
        }
        
        stage('Install Dependencies') {
            steps {
                sh 'npm install'
            }
        }
        
        stage('Test') {
            steps {
                sh 'npm test'
            }
        }
        
        stage('Build') {
            steps {
                sh 'npm run build'
            }
        }
        
        stage('Deploy') {
            steps {
                sh './deploy.sh'
            }
        }
    }
}

Multi-Environment Deployment

For teams managing staging and production environments, Jenkins can automate promotions between environments based on test results and manual approvals. This prevents broken code from reaching production while maintaining rapid deployment cycles.

Automated Testing Integration

Jenkins excels at running comprehensive test suites including unit tests, integration tests, and end-to-end testing. Teams often configure Jenkins to run different test levels based on the branch being built – quick smoke tests for feature branches and full test suites for main branch commits.

Jenkins vs. Alternative CI/CD Solutions

While Jenkins remains popular, it’s worth understanding how it compares to other CI/CD solutions:

Feature Jenkins GitLab CI GitHub Actions CircleCI
Cost Free (self-hosted) Free tier + paid Free tier + paid Free tier + paid
Plugin Ecosystem 1,800+ plugins Built-in features Growing marketplace Limited extensions
Setup Complexity High Medium Low Low
Customization Extremely High High Medium Medium
Maintenance Overhead High Low-Medium None None

Jenkins makes sense when you need maximum flexibility and don’t mind the operational overhead. For teams wanting managed solutions, cloud-based alternatives might be more suitable.

Advanced Configuration Tips

Once Jenkins is running smoothly, consider these advanced configurations for production environments:

Backup Strategy

Regular backups are essential for production Jenkins instances:

# Create backup script
sudo nano /opt/jenkins-backup.sh

#!/bin/bash
BACKUP_DIR="/opt/jenkins-backups"
JENKINS_HOME="/var/lib/jenkins"
DATE=$(date +%Y%m%d_%H%M%S)

mkdir -p $BACKUP_DIR
tar -czf $BACKUP_DIR/jenkins-backup-$DATE.tar.gz -C $JENKINS_HOME .

# Keep only last 7 backups
find $BACKUP_DIR -name "jenkins-backup-*.tar.gz" -mtime +7 -delete

# Make script executable
sudo chmod +x /opt/jenkins-backup.sh

# Add to crontab for daily backups
echo "0 2 * * * /opt/jenkins-backup.sh" | sudo crontab -

SSL/TLS Configuration

For production deployments, enabling HTTPS is non-negotiable. Using Let’s Encrypt with your Nginx reverse proxy provides free SSL certificates:

# Install Certbot
sudo apt install certbot python3-certbot-nginx -y

# Obtain SSL certificate
sudo certbot --nginx -d your-domain.com

# Test automatic renewal
sudo certbot renew --dry-run

Build Agent Configuration

Distributing builds across multiple agents improves performance and reliability. Set up build agents on separate servers to handle different types of workloads – one for Docker builds, another for mobile app compilation, etc.

Jenkins on Ubuntu 24 provides a solid foundation for automating your development workflows. The key to success lies in proper initial configuration, regular maintenance, and gradually building complexity as your team’s needs grow. Start with basic pipelines and evolve your setup based on real usage patterns rather than trying to implement everything at once.

For detailed configuration options and advanced features, check the official Jenkins documentation. The Jenkins community is also incredibly helpful – their community forums contain solutions to virtually every challenge you might encounter.



This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.

This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.

Leave a reply

Your email address will not be published. Required fields are marked