How to Install Jenkins on Ubuntu: Step-by-Step Guide
To install
Jenkins on Ubuntu, first add the Jenkins repository key and source, then update your package list and install Jenkins using apt. Finally, start and enable the Jenkins service to run it automatically.Syntax
These are the main commands to install Jenkins on Ubuntu:
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -: Adds the Jenkins repository key.sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list': Adds Jenkins repository to your system.sudo apt update: Updates the package list.sudo apt install jenkins: Installs Jenkins.sudo systemctl start jenkins: Starts Jenkins service.sudo systemctl enable jenkins: Enables Jenkins to start on boot.
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
Example
This example shows the full process of installing Jenkins on Ubuntu, including checking the service status and retrieving the initial admin password.
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 sudo systemctl status jenkins sudo cat /var/lib/jenkins/secrets/initialAdminPassword
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; 10s ago
Docs: https://www.jenkins.io/doc/
Main PID: 1234 (java)
Tasks: 25 (limit: 4915)
Memory: 150.0M
CGroup: /system.slice/jenkins.service
└─1234 /usr/bin/java -jar /usr/share/jenkins/jenkins.war
f3b1c2d4e5f678901234567890abcdef
Common Pitfalls
Common mistakes when installing Jenkins on Ubuntu include:
- Not adding the Jenkins repository key, which causes package installation to fail.
- Skipping
apt updateafter adding the repository, so the system doesn't see Jenkins packages. - Not starting or enabling the Jenkins service, so Jenkins won't run or start on reboot.
- Trying to access Jenkins before retrieving the initial admin password.
bash
sudo apt install jenkins # This will fail if the repository key and source are not added first. # Correct way: 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
Quick Reference
Summary tips for installing Jenkins on Ubuntu:
- Always add the Jenkins repository key before installing.
- Run
sudo apt updateafter adding new repositories. - Use
sudo systemctl start jenkinsandsudo systemctl enable jenkinsto run Jenkins immediately and on boot. - Find the initial admin password at
/var/lib/jenkins/secrets/initialAdminPasswordto unlock Jenkins in the browser.
Key Takeaways
Add Jenkins repository key and source before installing to avoid errors.
Always run sudo apt update after adding new repositories.
Start and enable Jenkins service to run it now and on system boot.
Retrieve the initial admin password to access Jenkins web interface.
Follow commands exactly to ensure a smooth Jenkins installation on Ubuntu.