Install Java 21 (OpenJDK)

sudo apt update
sudo apt install fontconfig openjdk-21-jre

Check Java version

java --version
ubuntu@jenkins-test:~$ java --version
openjdk 21.0.3 2024-04-16
OpenJDK Runtime Environment (build 21.0.3+9-Ubuntu-1ubuntu1)
OpenJDK 64-Bit Server VM (build 21.0.3+9-Ubuntu-1ubuntu1, mixed mode, sharing)

Go to Jenkins official download page click here

Click on Linux

jenkins-install-official

Click on Debian/Ubuntu

Follow the commands in Long Term Support release section

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
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
sudo apt-get update
sudo apt-get install jenkins

Check Jenkins running status

sudo systemctl status jenkins
ubuntu@jenkins-test:~$ sudo systemctl status jenkins
● jenkins.service - Jenkins Continuous Integration Server
     Loaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; preset: enabled)
     Active: active (running) since Sat 2024-07-06 14:18:41 UTC; 22s ago
   Main PID: 6539 (java)
      Tasks: 50 (limit: 4627)
     Memory: 1.1G (peak: 1.1G)
        CPU: 37.256s
     CGroup: /system.slice/jenkins.service
             └─6539 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPor

Enable Jenkins to automatically start after reboot

sudo systemctl enable jenkins
ubuntu@jenkins-test:~$ sudo systemctl enable jenkins
Synchronizing state of jenkins.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install enable jenkins