Ubuntek Banner

Install Jenkins on Ubuntu

Devops & Automation Intermediate 15 minutes

Summary

Jenkins is an open-source automation server that enables developers to build, test, and deploy their software. This tutorial will guide you through installing Jenkins on Ubuntu, including Java setup, repository configuration, and initial configuration.

Key Vocabulary

Jenkins: An open-source automation server for CI/CD pipelines.
CI/CD: Continuous Integration/Continuous Deployment - practices for automating software delivery.
Pipeline: A series of automated steps that build, test, and deploy software.
Webhook: A way for applications to communicate automatically when events occur.
Artifact: A file or set of files produced as a result of a build process.

Prerequisites

  • Ubuntu 20.04 or later
  • Sudo/root access
  • Internet connection
  • At least 2GB RAM recommended

Step-by-Step Instructions

Step 1

Update Package Repository

Update the package repository to ensure you have the latest package information.

sudo apt update -y
Why this works: Updates the package lists and ensures you can install the latest versions of packages.
Step 2

Install Java 21

Install OpenJDK 21, which is required for Jenkins to run.

sudo apt install openjdk-21-jdk -y
Why this works: Jenkins requires Java to run. OpenJDK 21 is the recommended version for Jenkins.
Step 3

Verify Java Installation

Check that Java is properly installed and accessible.

java -version
Why this works: This command displays the Java version to confirm the installation was successful.
Step 4

Download Jenkins GPG Key

Download and add the Jenkins GPG key for package verification.

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
Why this works: This GPG key is used to verify that Jenkins packages are authentic and haven't been tampered with.
Step 5

Add Jenkins Repository

Add the official Jenkins repository to your system's package 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
Why this works: This adds the Jenkins repository to your apt sources, allowing you to install Jenkins using apt.
Step 6

Update Package Lists Again

Update package lists to include the new Jenkins repository.

sudo apt update -y
Why this works: Refreshes the package lists to include Jenkins packages from the newly added repository.
Step 7

Install Jenkins

Install the Jenkins package using apt.

sudo apt install jenkins -y
Why this works: Installs Jenkins and all its dependencies on your system.
Step 8

Start and Enable Jenkins

Start the Jenkins service and enable it to start automatically on boot.

sudo systemctl start jenkins && sudo systemctl enable jenkins
Why this works: Starts Jenkins immediately and configures it to start automatically when the system boots.
Step 9

Check Jenkins Status

Verify that Jenkins is running properly.

sudo systemctl status jenkins
Why this works: Shows the current status of the Jenkins service to confirm it's running.
Step 10

Get Initial Admin Password

Retrieve the initial administrator password for Jenkins setup.

sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Why this works: Displays the initial admin password needed to complete Jenkins setup in the web interface.
Step 11

Access Jenkins Web Interface

Open Jenkins in your web browser to complete the setup.

<server-ip>:8080
Why this works: Access Jenkins through your web browser using your server's IP address and port 8080 to complete the initial setup.
⚠️ Warning: Make sure port 8080 is open in your firewall if accessing remotely.

Common Issues & Solutions

Problem: Jenkins fails to start
Solution: Check if Java is properly installed with 'java -version'. Ensure you have sufficient RAM (at least 2GB recommended).
Problem: Port 8080 is already in use
Solution: Check what service is using port 8080 with 'sudo netstat -tulpn | grep :8080' and stop the conflicting service.
Problem: Cannot access Jenkins web interface
Solution: Ensure your firewall allows traffic on port 8080. Use 'sudo ufw allow 8080' if using UFW.
Problem: Initial admin password file not found
Solution: Wait a moment for Jenkins to fully start up, then check the path again. The file is created during Jenkins startup.

Conclusion

Congratulations! You have successfully installed Jenkins on your Ubuntu system. Jenkins is now running and ready to be configured for your CI/CD pipelines.

Next steps:

  • Access Jenkins at http://your-server-ip:8080
  • Use the initial admin password to complete setup
  • Install recommended plugins
  • Create your first admin user
  • Start building your first pipeline!