Bird
Raised Fist0
Jenkinsdevops~10 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What is the first step before installing Jenkins on a Linux system?
easy
A. Create a Jenkins user account manually
B. Start the Jenkins service immediately
C. Add Jenkins repository key without installing Java
D. Install Java (OpenJDK) because Jenkins requires it to run

Solution

  1. Step 1: Understand Jenkins prerequisites

    Jenkins requires Java to run, so Java must be installed first.
  2. Step 2: Confirm prerequisite installation order

    Installing Java first ensures Jenkins can run properly after installation.
  3. Final Answer:

    Install Java (OpenJDK) because Jenkins requires it to run -> Option D
  4. Quick Check:

    Java installation is the first step [OK]
Hint: Always install Java before Jenkins on Linux [OK]
Common Mistakes:
  • Trying to start Jenkins before Java is installed
  • Skipping Java installation
  • Adding repository key before Java
2. Which command correctly adds the Jenkins repository key on a Debian-based Linux system?
easy
A. curl https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-get update
B. sudo rpm --import https://pkg.jenkins.io/debian-stable/jenkins.io.key
C. wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
D. sudo apt-get install jenkins-key

Solution

  1. Step 1: Identify the correct key import command for Debian

    Debian uses apt-key to add repository keys, and wget with pipe is common.
  2. Step 2: Verify command syntax

    The command uses wget to download the key and pipes it to apt-key add, which is correct.
  3. Final Answer:

    wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add - -> Option C
  4. Quick Check:

    apt-key add with wget is correct for Debian [OK]
Hint: Use wget and apt-key to add Jenkins key on Debian [OK]
Common Mistakes:
  • Using rpm commands on Debian
  • Trying to install a non-existent package 'jenkins-key'
  • Using curl without proper piping
3. After adding the Jenkins repository and updating package lists, what is the output of the command sudo systemctl status jenkins immediately after installation but before starting Jenkins?
medium
A. Active: active (running)
B. Active: inactive (dead)
C. Active: failed
D. Unit jenkins.service could not be found

Solution

  1. Step 1: Understand Jenkins service state after installation

    Installing Jenkins does not start the service automatically; it remains inactive.
  2. Step 2: Interpret systemctl status output

    Since Jenkins is not started yet, status shows inactive (dead), not running or failed.
  3. Final Answer:

    Active: inactive (dead) -> Option B
  4. Quick Check:

    Service inactive before start command [OK]
Hint: Service is inactive until explicitly started [OK]
Common Mistakes:
  • Assuming service auto-starts after install
  • Confusing 'failed' with 'inactive'
  • Expecting 'unit not found' after install
4. You installed Jenkins on Linux but the command sudo systemctl start jenkins fails with 'Failed to start jenkins.service: Unit not found.' What is the most likely cause?
medium
A. Jenkins package was not installed properly or repository not added
B. Java is not installed on the system
C. Firewall is blocking Jenkins port 8080
D. You need to reboot the system before starting Jenkins

Solution

  1. Step 1: Analyze the error message

    'Unit not found' means systemd cannot find the Jenkins service file, likely missing installation.
  2. Step 2: Identify common causes

    Missing or incorrect repository setup or failed package install causes service file absence.
  3. Final Answer:

    Jenkins package was not installed properly or repository not added -> Option A
  4. Quick Check:

    Missing service file means Jenkins not installed correctly [OK]
Hint: Check Jenkins package and repo if service unit missing [OK]
Common Mistakes:
  • Blaming firewall for service start failure
  • Assuming Java missing causes 'unit not found'
  • Thinking reboot fixes missing service unit
5. You want to install Jenkins on a Linux server and ensure it starts automatically on boot. Which sequence of commands correctly achieves this?
hard
A. sudo apt install openjdk-11-jdk; add Jenkins repo and key; sudo apt update; sudo apt install jenkins; sudo systemctl enable jenkins; sudo systemctl start jenkins
B. sudo apt install jenkins; sudo systemctl start jenkins; sudo apt install openjdk-11-jdk; sudo systemctl enable jenkins
C. sudo systemctl start jenkins; sudo apt install openjdk-11-jdk; sudo apt install jenkins; sudo systemctl enable jenkins
D. sudo apt update; sudo apt install jenkins; sudo systemctl enable jenkins; sudo systemctl start jenkins

Solution

  1. Step 1: Install Java before Jenkins

    Jenkins requires Java, so install OpenJDK first to avoid runtime errors.
  2. Step 2: Add Jenkins repository and key, update package list, then install Jenkins

    Adding repo and key ensures latest Jenkins version is installed properly.
  3. Step 3: Enable Jenkins service to start on boot and start it now

    Enabling service ensures Jenkins auto-starts on reboot; starting it activates Jenkins immediately.
  4. Final Answer:

    sudo apt install openjdk-11-jdk; add Jenkins repo and key; sudo apt update; sudo apt install jenkins; sudo systemctl enable jenkins; sudo systemctl start jenkins -> Option A
  5. Quick Check:

    Correct install order and enable/start commands [OK]
Hint: Install Java first, then Jenkins, enable and start service [OK]
Common Mistakes:
  • Installing Jenkins before Java
  • Skipping repository setup
  • Not enabling service for auto-start
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard