0
0
JenkinsHow-ToBeginner · 4 min read

How to Install Jenkins: Step-by-Step Guide

To install Jenkins, first add the official Jenkins repository and key, then update your package manager and install Jenkins using apt or yum. Finally, start the Jenkins service and access it via your browser on port 8080.
📐

Syntax

Installing Jenkins involves these main steps:

  • Add Jenkins repository and key: This allows your system to trust Jenkins packages.
  • Update package manager: Refresh package lists to include Jenkins.
  • Install Jenkins: Use your system's package manager to install.
  • Start Jenkins service: Enable and start Jenkins to run continuously.
bash
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install jenkins
sudo systemctl start jenkins
sudo systemctl enable jenkins
💻

Example

This example shows how to install Jenkins on a Debian-based system like Ubuntu.

It adds the Jenkins repository, updates packages, installs Jenkins, and starts the service.

bash
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install -y jenkins
sudo systemctl start jenkins
sudo systemctl enable jenkins

# Check Jenkins status
sudo systemctl status jenkins
Output
● jenkins.service - Jenkins Continuous Integration Server Loaded: loaded (/lib/systemd/system/jenkins.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2024-06-20 10:00:00 UTC; 1min ago Main PID: 12345 (java) Tasks: 30 (limit: 4915) Memory: 200.0M CGroup: /system.slice/jenkins.service └─12345 /usr/bin/java -jar /usr/share/jenkins/jenkins.war
⚠️

Common Pitfalls

Common mistakes when installing Jenkins include:

  • Not adding the Jenkins repository key, causing package verification errors.
  • Skipping apt update after adding the repository, so Jenkins packages are not found.
  • Not starting or enabling the Jenkins service, so Jenkins does not run automatically.
  • Firewall blocking port 8080, preventing web access.

Always check firewall settings and service status after installation.

bash
## Wrong: Installing Jenkins without adding repo key
sudo apt install jenkins

## Right: Add key and repo before installing
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update
sudo apt install jenkins
📊

Quick Reference

Summary tips for installing Jenkins:

  • Use official Jenkins repositories for latest stable versions.
  • Run sudo apt update after adding repos.
  • Start and enable Jenkins service with systemctl.
  • Access Jenkins at http://localhost:8080 after installation.
  • Check firewall rules to allow port 8080.

Key Takeaways

Add the official Jenkins repository and key before installing.
Always update your package manager after adding new repositories.
Start and enable the Jenkins service to run it continuously.
Access Jenkins on port 8080 via your web browser.
Check firewall settings if Jenkins web interface is unreachable.