0
0
Jenkinsdevops~10 mins

Installing on Linux in Jenkins - Step-by-Step CLI Walkthrough

Choose your learning style9 modes available
Introduction
Jenkins is a tool that helps automate tasks like building and testing software. Installing Jenkins on Linux lets you run these tasks on your own server easily.
When you want to automatically build your software every time you save changes.
When you need to run tests on your code without doing it manually.
When you want to schedule tasks like backups or deployments on your server.
When you want a web interface to manage your automation tasks.
When you want to share automation with your team on a central server.
Commands
This command updates the list of available packages and their versions on your Linux system.
Terminal
sudo apt update
Expected OutputExpected
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease Get:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] Get:3 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB] Fetched 215 kB in 1s (234 kB/s) Reading package lists... Done
Jenkins needs Java to run. This command installs Java 11, which Jenkins requires.
Terminal
sudo apt install openjdk-11-jdk -y
Expected OutputExpected
Reading package lists... Done Building dependency tree Reading state information... Done The following additional packages will be installed: openjdk-11-jdk-headless openjdk-11-jre openjdk-11-jre-headless Suggested packages: openjdk-11-demo openjdk-11-source visualvm The following NEW packages will be installed: openjdk-11-jdk openjdk-11-jdk-headless openjdk-11-jre openjdk-11-jre-headless 0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded. Need to get 36.9 MB of archives. After this operation, 105 MB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 openjdk-11-jre-headless amd64 11.0.11+9-0ubuntu2~20.04 [36.1 MB] Fetched 36.1 MB in 3s (11.7 MB/s) Selecting previously unselected package openjdk-11-jre-headless:amd64. (Reading database ... 123456 files and directories currently installed.) Preparing to unpack .../openjdk-11-jre-headless_11.0.11+9-0ubuntu2~20.04_amd64.deb ... Unpacking openjdk-11-jre-headless:amd64 (11.0.11+9-0ubuntu2~20.04) ... Setting up openjdk-11-jre-headless:amd64 (11.0.11+9-0ubuntu2~20.04) ... Processing triggers for man-db (2.9.1-1) ...
-y - Automatically answer yes to prompts
This command downloads and adds the Jenkins repository key to your system to verify Jenkins packages.
Terminal
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
Expected OutputExpected
OK
-q - Quiet mode, no output from wget
-O - - Output to standard output for piping
This command adds the Jenkins package repository to your system's package sources.
Terminal
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
Expected OutputExpected
No output (command runs silently)
Update package lists again to include Jenkins packages from the new repository.
Terminal
sudo apt update
Expected OutputExpected
Hit:1 http://archive.ubuntu.com/ubuntu focal InRelease Get:2 https://pkg.jenkins.io/debian-stable binary/ InRelease [4,832 B] Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] Get:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB] Fetched 220 kB in 1s (234 kB/s) Reading package lists... Done
This command installs Jenkins on your Linux system.
Terminal
sudo apt install jenkins -y
Expected OutputExpected
Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: jenkins 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 120 MB of archives. After this operation, 400 MB of additional disk space will be used. Get:1 https://pkg.jenkins.io/debian-stable binary/ jenkins all 2.387.3 [120 MB] Fetched 120 MB in 10s (12.0 MB/s) Selecting previously unselected package jenkins. (Reading database ... 123789 files and directories currently installed.) Preparing to unpack .../jenkins_2.387.3_all.deb ... Unpacking jenkins (2.387.3) ... Setting up jenkins (2.387.3) ... Created symlink /etc/systemd/system/multi-user.target.wants/jenkins.service → /lib/systemd/system/jenkins.service. Processing triggers for systemd (245.4-4ubuntu3.13) ...
-y - Automatically confirm installation
Starts the Jenkins service so it runs in the background.
Terminal
sudo systemctl start jenkins
Expected OutputExpected
No output (command runs silently)
Checks if Jenkins is running properly after starting it.
Terminal
sudo systemctl status jenkins
Expected OutputExpected
● jenkins.service - Jenkins Continuous Integration Server Loaded: loaded (/lib/systemd/system/jenkins.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2024-06-07 12:00:00 UTC; 5s ago Main PID: 12345 (java) Tasks: 30 (limit: 4915) Memory: 300.0M CGroup: /system.slice/jenkins.service └─12345 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/jenkins/jenkins.war Jun 07 12:00:00 ubuntu systemd[1]: Started Jenkins Continuous Integration Server.
Allows network traffic on port 8080, which Jenkins uses by default.
Terminal
sudo ufw allow 8080
Expected OutputExpected
Rule added Rule added (v6)
Key Concept

If you remember nothing else from this pattern, remember: Jenkins requires Java and a repository setup before installation on Linux.

Common Mistakes
Skipping Java installation before installing Jenkins
Jenkins needs Java to run; without it, Jenkins will not start.
Always install a supported Java version like openjdk-11-jdk before installing Jenkins.
Not adding the Jenkins repository key and source
Without the repository, your system cannot find the Jenkins package or verify its authenticity.
Add the Jenkins repository key and source list before running apt update and installing Jenkins.
Not opening port 8080 in the firewall
Jenkins runs on port 8080 by default; if the port is blocked, you cannot access Jenkins web interface.
Use firewall commands like 'sudo ufw allow 8080' to open the port.
Summary
Update your package list and install Java before Jenkins.
Add Jenkins repository key and source to your system.
Install Jenkins and start its service.
Check Jenkins service status to confirm it is running.
Open port 8080 in the firewall to access Jenkins web interface.