Setting Up Jenkins on Ubuntu: A Beginner's Guide
Table of contents
- Introduction
- What is Jenkins?
- Why Use Jenkins?
- How to Set Up Jenkins on Ubuntu
- Step 1: Update Your System
- Step 2: Install Java
- Step 3: Add Jenkins Repository
- Step 4: Install Jenkins
- Step 5: Start and Enable Jenkins Service
- Step 6: Configure Firewall (if necessary)
- Step 7: Access Jenkins
- Step 8: Unlock Jenkins
- Step 9: Install Recommended Plugins
- Step 10: Create an Admin User
- Step 11: Configure Jenkins URL
- Step 12: Jenkins Dashboard
Introduction
If you're new to DevOps or Continuous Integration/Continuous Delivery (CI/CD), you might have heard of Jenkins as a crucial tool for automating development workflows. In this guide, we'll explore what Jenkins is, why it's essential for modern development, and how to set up Jenkins on Ubuntu Linux from scratch.
What is Jenkins?
Jenkins is an open-source automation tool written in Java that helps developers automate tasks such as building, testing, and deploying code. It’s widely used in DevOps practices and supports Continuous Integration (CI) and Continuous Delivery (CD) workflows.
In a CI/CD pipeline, Jenkins automatically triggers tasks based on code changes. This can include running tests, checking code quality, and deploying applications. Jenkins’ vast plugin ecosystem makes it flexible and adaptable for nearly any software project.
Why Use Jenkins?
Using Jenkins can provide several benefits, including:
Automated Workflows: Jenkins saves time by automating repetitive tasks.
Improved Code Quality: By running tests and quality checks automatically, Jenkins helps ensure a consistent standard.
Faster Deployment: Jenkins speeds up the deployment process, reducing the time it takes to release new features or updates.
Team Collaboration: Jenkins helps teams work together efficiently by notifying them about build status and test results.
How to Set Up Jenkins on Ubuntu
Now, let’s walk through a step-by-step setup of Jenkins on Ubuntu Linux. This tutorial will be for Jenkins LTS (Long-Term Support), which is stable and ideal for beginners.
Step 1: Update Your System
Before installing Jenkins, update your system to ensure all packages are up-to-date:
sudo apt update && sudo apt upgrade -y
Step 2: Install Java
Jenkins requires Java to run. Install OpenJDK 11, which is supported by Jenkins:
sudo apt install openjdk-11-jdk -y
To verify the installation, check the Java version:
java -version
You should see a version output similar to openjdk version "11.0.x"
.
Step 3: Add Jenkins Repository
Since Jenkins is not in the default Ubuntu repositories, add the official Jenkins repository.
Import the Jenkins GPG Key:
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io.key | sudo tee \ /usr/share/keyrings/jenkins-keyring.asc > /dev/null
Add the Jenkins Repository to Your System:
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \ https://pkg.jenkins.io/debian binary/ | sudo tee \ /etc/apt/sources.list.d/jenkins.list > /dev/null
Step 4: Install Jenkins
After adding the repository, update your package list and install Jenkins:
sudo apt update
sudo apt install jenkins -y
This will download and install Jenkins and all necessary dependencies.
Step 5: Start and Enable Jenkins Service
After the installation, start Jenkins and enable it to start at boot:
sudo systemctl start jenkins
sudo systemctl enable jenkins
Step 6: Configure Firewall (if necessary)
Jenkins runs on port 8080 by default. Allow traffic on this port:
sudo ufw allow 8080
sudo ufw reload
Step 7: Access Jenkins
Now, open a web browser and go to:
http://your_server_ip:8080
Replace your_server_ip
with your actual server’s IP address. You should see Jenkins' setup wizard.
Step 8: Unlock Jenkins
During the first setup, Jenkins will prompt for an initial admin password. To retrieve this password, run:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy the password and paste it into the browser to proceed.
Step 9: Install Recommended Plugins
After unlocking Jenkins, the setup wizard will offer you a choice of plugins. Select Install suggested plugins to get started with commonly used plugins.
The installation process will take a few minutes.
Step 10: Create an Admin User
Once plugins are installed, Jenkins will prompt you to create an admin user. Fill out the form with your username, password, and email address.
Step 11: Configure Jenkins URL
Jenkins will prompt you to confirm the URL. Ensure it’s correct (it should auto-detect). If it looks good, click Save and Finish.
Step 12: Jenkins Dashboard
After setup, you’ll be taken to the Jenkins Dashboard. Here, you can start creating jobs, setting up pipelines, and exploring Jenkins’ features.
Basic Jenkins Setup Commands Summary
For quick reference, here’s a summary of the essential setup commands:
Update System:
sudo apt update && sudo apt upgrade -y
Install Java:
sudo apt install openjdk-11-jdk -y
Add Jenkins Repository:
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian 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
Access Jenkins:
- Go to
http://your_server_ip:8080
in a web browser.
- Go to
Conclusion
Jenkins is a powerful automation tool that can streamline your software development process. In this tutorial, we covered what Jenkins is, why it’s beneficial, and how to set it up on Ubuntu Linux. By following these steps, you now have a functional Jenkins installation where you can start building CI/CD pipelines and automating workflows. Enjoy exploring Jenkins!
Tags: #Jenkins #DevOps #Ubuntu #CICD #ContinuousIntegration #BeginnerFriendly #Automation
Subscribe to my newsletter
Read articles from CHETAN BARDOLE directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
CHETAN BARDOLE
CHETAN BARDOLE
Aspiring DevOps Engineer