JENKINS Installation

Nagesh PReddyNagesh PReddy
3 min read

To install Jenkins for CI/CD on Ubuntu, follow these step-by-step instructions. Below, I’ll also highlight common installation issues with examples to help you troubleshoot effectively.

Step-by-Step Installation of Jenkins on Ubuntu

  1. Update the System Ensure your package list and installed packages are up to date.

     sudo apt update && sudo apt upgrade -y
    
  2. Install Java Jenkins requires Java. Install OpenJDK 11, which is compatible with most Jenkins versions.

     sudo apt install openjdk-11-jre -y
    

    Verify the installation:

     java -version
    

    Expected output should show Java version 11.

  3. Add Jenkins Repository Import the GPG key and add the Jenkins repository.

     curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
     echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
    
  4. Update Package List Refresh the package index to include the Jenkins repository.

     sudo apt update
    
  5. Install Jenkins Install Jenkins using the apt package manager.

     sudo apt install jenkins -y
    
  6. Start and Enable Jenkins Service Start the Jenkins service and enable it to run on boot.

     sudo systemctl start jenkins
     sudo systemctl enable jenkins
    
  7. Check Jenkins Status Verify that Jenkins is running.

     sudo systemctl status jenkins
    

    Look for active (running) in the output.

  8. Configure Firewall Allow traffic on port 8080 (default Jenkins port).

     sudo ufw allow 8080
     sudo ufw enable
    
  9. Access Jenkins Web Interface Open a browser and navigate to http://your_server_ip:8080. Retrieve the initial admin password:

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

    Enter this password on the setup page, then follow the prompts to install plugins and create an admin user.

  10. Complete Setup

    • Install suggested plugins.

    • Create an admin user.

    • Save the instance configuration (default URL is fine).

Jenkins is now installed and ready for CI/CD pipeline configuration.


Common Installation Issues with Examples

  1. Java Not Installed or Incorrect Version

    • Issue: If Java is missing or an incompatible version (e.g., Java 17) is installed, Jenkins fails to start.

    • Example: Running sudo systemctl status jenkins shows Job for jenkins.service failed because the control process exited with error code.

    • Solution: Uninstall existing Java and install OpenJDK 11.

        sudo apt remove --purge openjdk*
        sudo apt install openjdk-11-jre -y
        sudo systemctl restart jenkins
      
  2. Repository Key Error

    • Issue: The GPG key import fails, leading to a 404 error or repository not found.

    • Example: apt update outputs The following signatures couldn't be verified because the public key is not available.

    • Solution: Ensure the correct key URL is used. Retry the key import and update.

        curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
        sudo apt update
      
  3. Port 8080 Already in Use

    • Issue: Another service (e.g., Apache) is using port 8080, causing Jenkins to fail.

    • Example: Browser shows "Connection refused" or sudo systemctl status jenkins indicates a bind failure.

    • Solution: Change Jenkins port or stop the conflicting service.

        sudo nano /etc/default/jenkins
      

      Edit HTTP_PORT=8081, then restart Jenkins:

        sudo systemctl restart jenkins
      
  4. Service Fails to Start

    • Issue: Insufficient permissions or misconfiguration prevents Jenkins from starting.

    • Example: sudo systemctl start jenkins fails with no clear error in status.

    • Solution: Check logs for details.

        sudo journalctl -u jenkins.service
      

      Ensure the jenkins user has proper permissions on /var/lib/jenkins.

  5. Firewall Blocks Access

    • Issue: UFW is enabled but port 8080 is not allowed, blocking web access.

    • Example: Browser shows "This site can’t be reached" despite Jenkins running.

    • Solution: Verify and allow the port.

        sudo ufw status
        sudo ufw allow 8080
      

0
Subscribe to my newsletter

Read articles from Nagesh PReddy directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Nagesh PReddy
Nagesh PReddy