2024-12-16DevOpsN Team

How to Install Jenkins on Ubuntu: CI/CD Configuration Guide

JenkinsDevOpsCI/CDUbuntuLinux
H

How to Install Jenkins on Ubuntu: CI/CD Configuration Guide

If you're building a CI/CD workflow for your Laravel, Node.js, or any backend project, Jenkins is one of the most reliable automation tools you can add to your stack. With Jenkins, you can automate everything from pulling the latest code, running tests, building artifacts, to deploying your application. In short, it lets you focus more on writing code and less on repetitive tasks.

In this guide, you'll learn how to install Jenkins on an Ubuntu server, configure it properly, open the right ports, and make sure you can access the Jenkins dashboard from your browser without running into annoying connection issues.

1. What Is Jenkins?

Jenkins is an automation server built to streamline your CI/CD workflow. It handles tasks that developers usually run manually, including:

  • Fetching the latest code from Git
  • Running tests
  • Building applications
  • Deploying to production or staging environments
  • Restarting services

Once set up, it can automatically run your entire deployment pipeline as part of your DevOps process every time you push new code.

2. Before You Begin: Server Requirements

For this tutorial, make sure you already have:

  • Ubuntu Server (22.04 or 24.04)
  • SSH access
  • Java (required for Jenkins)

First, update your server:

sudo apt update

Then install Java:

sudo apt install fontconfig openjdk-17-jre -y

Once Java is ready, you can move on to installing Jenkins.

3. Adding the Official Jenkins Repository

Jenkins isn't included in Ubuntu's default repositories, so you need to add the Jenkins repo manually.

Add the 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 the Jenkins repository:

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

Install Jenkins:

sudo apt update
sudo apt install jenkins -y

Start Jenkins:

sudo systemctl start jenkins
sudo systemctl enable jenkins

Check whether Jenkins is running:

sudo systemctl status jenkins

If the status shows "active (running)", the installation succeeded.

4. Verify Jenkins Port Availability

By default, Jenkins runs on port 8080. To confirm the service is listening:

sudo ss -tulpn | grep 8080

You should see something like:

LISTEN ... 0.0.0.0:8080

This means Jenkins is ready to accept connections.

5. Access Jenkins From Your Browser

Open your browser and visit: http://YOUR-SERVER-IP:8080

If you see the "Unlock Jenkins" page, you're good to go.

6. Get the Initial Admin Password

Jenkins requires a one-time admin password stored on your server. Run:

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

Copy the generated password, paste it into the web UI, and continue with the recommended plugin installation. You can install plugins for Docker and Kubernetes integrations later.

7. What to Do if You Can't Access Jenkins

This is the most common issue, especially on AWS EC2 or VPS providers using strict firewall rules.

A. Open Port 8080 on AWS Security Groups

If you are using Amazon EKS or EC2, add an inbound rule:

  • Type: Custom TCP
  • Port: 8080
  • Source: 0.0.0.0/0 (or your IP for security)

B. Allow Port 8080 via UFW

If UFW is active:

sudo ufw allow 8080
sudo ufw reload

After updating both firewall layers, Jenkins should be accessible immediately.

8. (Optional) Change the Default Jenkins Port

If another service uses 8080, or you prefer a safer port, you can change it to 8081:

sudo nano /etc/default/jenkins

Modify HTTP_PORT=8080 to HTTP_PORT=8081 and restart Jenkins:

sudo systemctl restart jenkins

Now access Jenkins through http://YOUR-SERVER-IP:8081. Don't forget to open port 8081 in your firewall.