How to Install Jenkins on Rocky Linux 9

Updated on 27 March, 2025
How to Install Jenkins on Rocky Linux 9 header image

Jenkins is a popular open-source automation server that enables continuous integration (CI) and continuous deployment (CD) in software development. Written in Java, Jenkins allows software developers to build, test, and deploy software. It provides many plugins to automate testing and manage changes in a large code base.

This article explains how to install Jenkins on Rocky Linux 9. You'll test the installation using the Jenkins dashboard and Jenkins CLI, and optimize Jenkins for maximum performance.

Prerequisites

Before you begin, you need to:

Install Java

Jenkins requires the Java development kit to run with all necessary dependecies. Follow the steps below to install the Java Development Kit (JDK) on your Rocky Linux 9 instance.

  1. Update the server’s package information index.

    console
    $ sudo dnf update -y
    
  2. Install OpenJDK 21, or replace it with the latest version available on the OpenJDK releases page.

    console
    $ sudo dnf install -y java-21-openjdk
    
  3. By default, your system may use a pre-installed older version of Java. Use the following command to check and switch to OpenJDK 21:

    console
    $ sudo alternatives --config java
    

    If your system has multiple versions of Java, you will see an output like the one below:

    There are two programs which provide 'java'.
    
      Selection    Command
    -----------------------------------------------
    *+ 1           java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.442.b06-2.el9.x86_64/jre/bin/java)
       2           java-21-openjdk.x86_64 (/usr/lib/jvm/java-21-openjdk-21.0.6.0.7-1.el9.x86_64/bin/java)
    
    Enter to keep the current selection[+], or type selection number:

    Type 2 to select OpenJDK 21.

  4. Verify the installation.

    console
    $ java -version
    

    Output:

    openjdk 21.0.6 2025-01-21 LTS
    OpenJDK Runtime Environment (Red_Hat-21.0.6.0.7-1) (build 21.0.6+7-LTS)
    OpenJDK 64-Bit Server VM (Red_Hat-21.0.6.0.7-1) (build 21.0.6+7-LTS, mixed mode, sharing)

Install Jenkins

Follow the steps below to install Jenkins on your Rocky Linux 9 workstation using the DNF package manager.

  1. Add the latest stable Jenkins repository to your DNF sources.

    console
    $ sudo wget https://pkg.jenkins.io/redhat-stable/jenkins.repo -O /etc/yum.repos.d/jenkins.repo
    
  2. Find the GPG key for your version from the same page and install it.

    console
    $ sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
    
  3. Install Jenkins.

    console
    $ sudo dnf install -y jenkins
    
  4. Start the Jenkins service.

    console
    $ sudo systemctl start jenkins
    
  5. Enable the Jenkins service to Start on Boot.

    console
    $ sudo systemctl enable jenkins
    
  6. Check its status.

    console
    $ sudo systemctl status jenkins
    

    Output:

    ● jenkins.service - Jenkins Continuous Integration Server
         Loaded: loaded (/usr/lib/systemd/system/jenkins.service; enabled; preset: disabled)
         Active: active (running) since Sun 2025-02-23 10:45:53 UTC; 21s ago
       Main PID: 5166 (java)
          Tasks: 44 (limit: 11059)
         Memory: 407.4M
            CPU: 12.385s
         CGroup: /system.slice/jenkins.service
                 └─5166 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
    Feb 23 10:45:47 test-server jenkins[5166]: 69638179145e4a3fa6826e5fe6c427da
    Feb 23 10:45:47 test-server jenkins[5166]: This may also be found at: /var/lib/jenkins/secrets/initialAdminPassword
    Feb 23 10:45:47 test-server jenkins[5166]: *************************************************************
    Feb 23 10:45:47 test-server jenkins[5166]: *************************************************************
    Feb 23 10:45:47 test-server jenkins[5166]: *************************************************************
    Feb 23 10:45:53 test-server jenkins[5166]: 2025-02-23 10:45:53.349+0000 [id=32]        INFO        jenkins.InitReactorRunner$1#onAttained: Completed initiali>
    Feb 23 10:45:53 test-server jenkins[5166]: 2025-02-23 10:45:53.367+0000 [id=24]        INFO        hudson.lifecycle.Lifecycle#onReady: Jenkins is fully up an>
    Feb 23 10:45:53 test-server systemd[1]: Started Jenkins Continuous Integration Server.
    Feb 23 10:45:55 test-server jenkins[5166]: 2025-02-23 10:45:55.036+0000 [id=47]        INFO        h.m.DownloadService$Downloadable#load: Obtained the update>
    Feb 23 10:45:55 test-server jenkins[5166]: 2025-02-23 10:45:55.038+0000 [id=47]        INFO        hudson.util.Retrier#start: Performed the action check upda>

Access the Jenkins Web Interface

Follow the steps to access the Jenkins web interface and complete the initial setup.

  1. Allow the default Jenkins port 8080 through the firewall to enable web access.

    console
    $ sudo firewall-cmd --permanent --zone=public --add-port=8080/tcp
    
  2. Reload the firewall to apply the new rule.

    console
    $ sudo firewall-cmd --reload
    
  3. Access the initial administrative password.

    console
    $ sudo cat /var/lib/jenkins/secrets/initialAdminPassword
    

    The output of this command is the password. Copy it.

  4. Open your web browser and access Jenkins using your domain name on port 8080.

    http://example.com:8080
  5. Paste the copied password in the Administrator Password field, and click Continue.

    Jenkins Admin Password Field

  6. Select the Install suggested Plugins to start installing all necessary Jenkins packages on your server.

    Customize Jenkins

    It will start to install the suggested plugins.

    Jenkins Plugins Installation

  7. The setup prompts you to enter the details of your first Admin User. Fill these fields and click the Save and Continue button to access the instance configuration page.

    Create First Admin User

  8. Enter or confirm the Jenkins URL, which should match your domain name.

    Confirm the Jenkins URL

  9. After entering the Jenkins URL, click the Save and Finish button.

    Jenkins Dashboard

  10. At last, click the Start using Jenkins button to access the Jenkins Dashboard.

    Last step of Jenkins setup

Secure Jenkins with Let's Encrypt SSL Certificates

Follow the steps below to install Nginx as a reverse proxy and generate Let's Encrypt SSL certificates using Certbot to secure the Jenkins web interface.

  1. Install the Nginx web server.

    console
    $ sudo dnf install nginx -y
    
  2. Install Certbot and the Nginx plugin.

    console
    $ sudo dnf install -y certbot python3-certbot-nginx
    
  3. Allow HTTP traffic.

    console
    $ sudo firewall-cmd --permanent --add-service=http
    
  4. Allow HTTPS traffic.

    console
    $ sudo firewall-cmd --permanent --add-service=https
    
  5. Reload the firewall to apply changes.

    console
    $ sudo firewall-cmd --reload
    
  6. Request an SSL certificate.

    console
    $ sudo certbot certonly --standalone -d example.com
    

    Certbot will present you with prompts in this sequence:

    1. Certbot first prompts you for an email address, enter an email ID. Enter an email address.
    2. It then asks you to read its terms of service and decide if you wish to proceed. Agree at this step.
    3. At last, it will ask you if you wish to share your email address with the Electronic Frontier Foundation. It is not compulsory to accept this, so you can deny by entering N.

    Your system now has a valid certificate for your domain name which it can use to establish TLS encryption for client sessions.

  7. Enable Nginx to start on boot and start the service.

    console
    $ sudo systemctl enable --now nginx
    
  8. Allow Jenkins to communicate over the network by enabling the necessary permissions.

    console
    $ sudo setsebool -P httpd_can_network_connect 1
    
  9. Open the Nginx configuration file.

    console
    $ sudo nano /etc/nginx/conf.d/jenkins.conf
    

    Add the following configuration.

    nginx
    server {
        listen 80;
        server_name example.com;
        return 301 https://$host$request_uri;
    }
    
    server {
        listen 443 ssl;
        server_name example.com;
    
        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    
        location / {
            proxy_pass http://127.0.0.1:8080;
    
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Port $server_port;
    
            # WebSocket Support for Jenkins
            proxy_http_version 1.1;
            proxy_request_buffering off;
            proxy_buffering off;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
        }
    }
    

    Save and close the file.

    Note
    In the jenkins.conf file, do not add https:// or / to your domain name in the server_name directive.
  10. Test the Nginx configuration.

    console
    $ sudo nginx -t
    

    Output:

    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
  11. Restart Nginx to apply the changes.

    console
    $ sudo systemctl restart nginx
    
  12. Open your browser and go to:

    https://example.com

    Jenkins should now be accessible over a secure HTTPS connection.

  13. To avoid a proxy setup error, change the Jenkins URL to HTTPS by navigating to Manage Jenkins > System in the Jenkins dashboard. Scroll down to the Jenkins Location section, update the Jenkins URL field from http://example.com:8080 to https://example.com/, and click the Save button to apply the changes.

    Change the Jenkins URL

  14. Restart Jenkins and apply the new URL setting.

    console
    $ sudo systemctl restart jenkins
    

Optimize Jenkins Performance

You can improve Jenkins's performance by adjusting system limits.

Configure System Limits

Follow the steps below to adjust system settings and allow Jenkins to handle more tasks.

  1. Open the limit configuration file.

    console
    $ sudo nano /etc/security/limits.conf
    

    Add the following lines before the #End of file comment to increase the maximum number of open files Jenkins can handle. It will prevent resource limitations that could affect Jenkins's performance under heavy workloads.

    text
    jenkins soft nofile 65536  
    jenkins hard nofile 65536
    

    Save and close the file.

  2. Restart Jenkins to apply the changes.

    console
    $ sudo systemctl restart jenkins
    
  3. Verify if the limits are applied.

    console
    $ cat /proc/$(pgrep -u jenkins java)/limits | grep "open files"
    

    Output:

    Max open files            524288               524288               files

Implement a Backup Strategy

Setting up regular backups can prevent data loss. Follow the steps below to back up Jenkins and automate the process.

  1. Create a folder to store backups.

    console
    $ mkdir ~/jenkins_backup
    
  2. Copy Jenkins data to the backup folder. This command copies all Jenkins configuration files, jobs, and user data.

    console
    $ sudo cp -r /var/lib/jenkins ~/jenkins_backup/
    
  3. To schedule automatic daily backups, edit your cron jobs.

    console
    $ crontab -e
    
  4. Add the following line at the button to run the backup every day at midnight.

    text
    0 0 * * * sudo cp -r /var/lib/jenkins ~/jenkins_backup/
    

    Save and exit the file.

  5. Check if the cron job was saved by running:

    console
    $ crontab -l
    

    If you see the backup job listed, it is set up.

  6. Verify the status of the cron service.

    console
    $ sudo systemctl status crond
    

    Output:

    ● crond.service - Command Scheduler
         Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; preset: enabled)
         Active: active (running) since Sun 2025-02-23 10:43:02 UTC; 1h 18min ago
       Main PID: 1348 (crond)
          Tasks: 1 (limit: 11059)
         Memory: 1.2M
            CPU: 66ms
         CGroup: /system.slice/crond.service
                 └─1348 /usr/sbin/crond -n
    Feb 23 10:43:02 test-server crond[1348]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 33% if used.)
    Feb 23 10:43:02 test-server crond[1348]: (CRON) INFO (running with inotify support)
    Feb 23 11:01:01 test-server CROND[5547]: (root) CMD (run-parts /etc/cron.hourly)
    Feb 23 11:01:01 test-server run-parts[5550]: (/etc/cron.hourly) starting 0anacron
    Feb 23 11:01:01 test-server run-parts[5556]: (/etc/cron.hourly) finished 0anacron
    Feb 23 11:01:01 test-server CROND[5546]: (root) CMDEND (run-parts /etc/cron.hourly)
    Feb 23 12:01:01 test-server CROND[9621]: (root) CMD (run-parts /etc/cron.hourly)
    Feb 23 12:01:01 test-server run-parts[9624]: (/etc/cron.hourly) starting 0anacron
    Feb 23 12:01:01 test-server run-parts[9630]: (/etc/cron.hourly) finished 0anacron
    Feb 23 12:01:01 test-server CROND[9620]: (root) CMDEND (run-parts /etc/cron.hourly)

    If the status is active, your backup job will run as scheduled.

Access and Test Jenkins

  1. Open Jenkins in your browser and sign in to the dashboard.

  2. Click the New Item button from the dashboard sidebar. Enter a job name, such as TestJob, and select the Freestyle Project option under the item type section, and click OK.

    Create a Job

  3. Scroll to the Build Step section and select Add build step > Execute shell.

    Configure Job

    Then, enter the following command:

    console
    $ echo "Hello, Jenkins!"
    

    Build steps command

  4. Click Save to apply the changes.

  5. Click Build Now to start the job.

    Build the Job

  6. Click the Build, for example, #1, to open the details.

    Job Details

  7. Click Console Output to view the build logs.

    Build Logs

    If you see this message, your Jenkins setup is successful.

Test Jenkins Using the Command Line

You can also verify the functionality of your Jenkins installation through the command line. This method uses Jenkins REST API and the Jenkins CLI.

  1. From the Jenkins dashboard, click your username in the top right corner and navigate to the Security tab.

    Access Security Tab

  2. Under the API Token section, click Add New Token, enter a token name, and click Generate. Copy and save the token in a secure location.

    Generate API Token

  3. Download the Jenkins CLI jar file.

    console
    $ wget https://example.com/jnlpJars/jenkins-cli.jar
    

    Replace example.com with your actual domain name.

  4. Move the Jenkins CLI jar file to a suitable location.

    console
    $ mv jenkins-cli.jar ~/jenkins-cli.jar
    
  5. Run the following command to check the connection.

    console
    $ java -jar ~/jenkins-cli.jar -s https://example.com/ -auth your_username:your_api_token version
    

    Replace your_username with your Jenkins username and your_api_token with your API token.

    Output:

    2.492.1
  6. Trigger the Test Job

    console
    $ java -jar ~/jenkins-cli.jar -s https://example.com/ -auth your_username:your_api_token build TestJob
    

    Wait a few moments for the build to complete.

  7. View build console output.

    console
    $ java -jar ~/jenkins-cli.jar -s https://example.com/ -auth your_username:your_api_token console TestJob
    

    Output:

    Running as SYSTEM
    Building in workspace /var/lib/jenkins/workspace/TestJob
    [TestJob] $ /bin/sh -xe /tmp/jenkins132166175190200986.sh
    + echo 'Hello, Jenkins!'
    Hello, Jenkins!
    Finished: SUCCESS

Conclusion

You have set up Jenkins on a Rocky Linux 9 instance and configured it for secure access. You created a sample job to verify its functionality and used the Jenkins CLI to manage jobs from the command line. You can now integrate Jenkins with version control systems, automate deployments, and scale your setup as needed. For advanced configurations and plugin options, refer to the Jenkins documentation.

Comments

No comments yet.