sodcalculator

10 Tech How-To

Install Jenkins Ubuntu: Step-by-Step Guide

Guide 10-4941 · Updated · Step by step

To install Jenkins on Ubuntu, you add the official Jenkins repository, import its GPG key, install the Jenkins package, and start the service. This guide covers the full process on Ubuntu 20.04 and 22.04, including initial setup, configuration, and common troubleshooting.

What Is Jenkins and Why Use It?

Jenkins is an open-source automation server used for continuous integration (CI) and continuous delivery (CD). It helps developers build, test, and deploy software automatically. Jenkins is written in Java and runs as a standalone application on any machine with a Java Runtime Environment (JRE). It is one of the most widely adopted CI/CD tools, with a large plugin ecosystem that integrates with version control systems like Git, build tools like Maven and Gradle, and cloud platforms.

On Ubuntu, Jenkins is typically installed as a systemd service, which means it starts automatically on boot and can be managed with standard commands like systemctl. The default installation uses port 8080 for its web interface.

Prerequisites

Before installing Jenkins, ensure your Ubuntu system meets these requirements:

  • Ubuntu 20.04 LTS or 22.04 LTS (64-bit). Jenkins also works on other versions, but these are the most common.
  • A user account with sudo privileges.
  • Java 11 or Java 17 (Jenkins 2.357 and later require Java 11; newer versions support Java 17). OpenJDK is recommended.
  • At least 2 GB of RAM and 20 GB of disk space for a basic setup, though requirements vary by project.
  • An internet connection to download packages.

If Java is not installed, you can install OpenJDK 11 with:

sudo apt update
sudo apt install openjdk-11-jre

Check the Java version with java -version to confirm.

Step-by-Step Installation

The recommended way to install Jenkins on Ubuntu is using the official Jenkins repository. This ensures you get the latest stable version and updates. Follow these steps:

  1. Add the Jenkins repository key and source list. The Jenkins project provides a Debian package repository. Run:
  2. curl -fsSL https://pkg.jenkins.io/debian-stable/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-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
    
  3. Update the package list and install Jenkins:
  4. sudo apt update
    sudo apt install jenkins
    
  5. Start the Jenkins service and enable it to run on boot:
  6. sudo systemctl start jenkins
    sudo systemctl enable jenkins
    
  7. Check the status to confirm it is running:
  8. sudo systemctl status jenkins
    

    You should see active (running) in the output.

If you prefer to install a specific version, you can list available versions with apt list -a jenkins and install with sudo apt install jenkins=<version>.

Initial Setup and Configuration

After installation, Jenkins is not yet ready to use. You need to unlock it with an initial admin password and create an admin user.

  1. Open your browser and go to http://your_server_ip:8080. You will see the “Unlock Jenkins� screen.
  2. Retrieve the initial admin password from the server. Run:
  3. sudo cat /var/lib/jenkins/secrets/initialAdminPassword
    
  4. Copy the password into the web form and click Continue.
  5. Choose “Install suggested plugins� to install the most common plugins (Git, Pipeline, etc.). This may take a few minutes.
  6. Create the first admin user: enter a username, password, full name, and email address. This becomes your login for the Jenkins dashboard.
  7. Set the Jenkins URL (default is fine) and finish the setup.

Once completed, you can start creating jobs and pipelines.

Common Problems and How to Fix Them

Jenkins installation usually goes smoothly, but you might encounter these issues:

  • Java version not supported: Jenkins 2.357+ requires Java 11 or 17. If you have Java 8, upgrade with sudo apt install openjdk-11-jre and update alternatives if needed.
  • Port 8080 already in use: If another service uses port 8080, either stop that service or change Jenkins’ port. Edit /etc/default/jenkins and set HTTP_PORT=8081, then restart Jenkins.
  • Cannot access the web interface: Check that the firewall allows port 8080. If using UFW, run sudo ufw allow 8080.
  • Jenkins service fails to start: Check logs with sudo journalctl -u jenkins to see the error. Often it’s a Java or permission issue.

If you need to restart Jenkins after configuration changes, use sudo systemctl restart jenkins.

Uninstalling Jenkins

To completely remove Jenkins from your Ubuntu system, follow these steps:

  1. Stop the service: sudo systemctl stop jenkins
  2. Remove the package: sudo apt remove --purge jenkins
  3. Delete the Jenkins home directory (contains all jobs and configurations): sudo rm -rf /var/lib/jenkins
  4. Remove the repository source: sudo rm /etc/apt/sources.list.d/jenkins.list and the keyring file if you added it.

Be careful: deleting /var/lib/jenkins erases all your jobs and settings. Back up this directory if you might need it later.

Alternatives to Jenkins

Jenkins is powerful but not the only CI/CD tool. Depending on your needs, you might consider:

  • GitLab CI/CD: Integrated with GitLab repositories, uses YAML-based pipelines, and is popular for Git-native workflows.
  • GitHub Actions: Built into GitHub, great for projects hosted there, with a large marketplace of pre-built actions.
  • Travis CI: A cloud-based CI service that was popular for open-source projects, though now less commonly used.
  • CircleCI: Known for speed and ease of configuration, especially for containerized builds.

Jenkins is often preferred when you need self-hosting, extensive plugin customization, or have existing infrastructure.

Frequently Asked Questions

Do I need to install Java separately?

Yes, Jenkins requires Java. The Jenkins package itself does not include Java. Install OpenJDK 11 or 17 before installing Jenkins. You can check if Java is already installed with java -version.

Can I install Jenkins using Docker instead?

Yes, Jenkins provides an official Docker image. You can run docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts. This is often easier for testing, but the native installation gives you more control over the system environment.

How do I change the Jenkins port?

Edit the file /etc/default/jenkins and change the HTTP_PORT value to your desired port. Then restart Jenkins with sudo systemctl restart jenkins. Make sure the new port is open in your firewall.

Where are Jenkins jobs stored?

Jenkins stores all jobs, configurations, and build logs in the Jenkins home directory, which is /var/lib/jenkins by default. Each job has a subdirectory under jobs/.

Is Jenkins free to use?

Yes, Jenkins is open-source and free to use. You only pay for the infrastructure you run it on. There is also a commercial offering called CloudBees Jenkins, but the core is free.

How do I update Jenkins to a newer version?

Since you installed from the official repository, simply run sudo apt update && sudo apt upgrade jenkins. This will update to the latest stable version in the repository. Always back up /var/lib/jenkins before upgrading.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →