How to Install Jenkins on Ubuntu

Install Jenkins on Ubuntu

Alright, let’s talk automation! If you’re diving into the world of Continuous Integration (CI) and Continuous Deployment (CD), you’ve undoubtedly heard of Jenkins. It’s the open-source automation server that has become a cornerstone for countless development teams worldwide. And what better platform to run it on than Ubuntu, the popular, stable, and user-friendly Linux distribution?

Getting Jenkins up and running on Ubuntu might seem daunting at first, but trust me, it’s totally achievable. This guide is designed to walk you through every single step, from preparing your system to completing the initial setup. We’ll break it down, keep it simple, and get you ready to automate your workflows in no time.

Table of Contents

Introduction: Why Jenkins on Ubuntu is a Match Made in DevOps Heaven

Before we roll up our sleeves and dive into the commands, let’s quickly touch upon why this combination is so powerful.

What Exactly is Jenkins? (The Automation Powerhouse)

Think of Jenkins as your tireless assistant for all things software development automation. At its core, Jenkins helps teams automate the different stages of the delivery pipeline, such as building, testing, and deploying software.

Imagine this: a developer pushes code changes. Jenkins automatically detects this, pulls the latest code, compiles it, runs automated tests (unit tests, integration tests, etc.), and if everything passes, maybe even deploys it to a staging or production environment. This whole process happens automatically, consistently, and often much faster than manual methods.

Key benefits include:

  • Faster Development Cycles: Automating builds and tests speeds things up significantly.
  • Improved Code Quality: Catching bugs early through automated testing saves headaches later.
  • Increased Reliability: Consistent, automated deployments reduce human error.
  • Extensibility: A massive ecosystem of plugins allows Jenkins to integrate with practically any tool or technology.

Why Choose Ubuntu for Your Jenkins Server?

Ubuntu is a fantastic choice for hosting Jenkins for several reasons:

  • Popularity & Community Support: It’s one of the most widely used Linux distributions, meaning vast amounts of documentation, tutorials (like this one!), and community support are available if you hit a snag.
  • Stability: Particularly the Long-Term Support (LTS) releases of Ubuntu offer a stable and reliable foundation for server applications like Jenkins.
  • Ease of Use: Compared to some other Linux distributions, Ubuntu is known for its relatively gentle learning curve and user-friendly package management (apt).
  • Security: Ubuntu has a strong focus on security with regular updates and tools like UFW (Uncomplicated Firewall) built-in.

What We’ll Cover in This Guide

We’re going end-to-end here. We’ll start with the essential prerequisites, ensuring your Ubuntu system is ready. Then, we’ll install Java (a must-have for Jenkins), add the official Jenkins repository, perform the actual installation, manage the Jenkins service, configure the firewall, and finally, walk through the crucial initial web-based setup. We’ll even throw in some troubleshooting tips for common hiccups. Ready? Let’s go!

Preparing Your Ubuntu System: Laying the Foundation

First things first, we need to make sure our Ubuntu server is prepped and ready for Jenkins. Skipping these steps can lead to installation failures or performance issues down the line.

Minimum System Requirements (Don’t Skimp Here!)

While Jenkins can run on modest hardware, for a smooth experience, especially as you add more jobs and complexity, you’ll want to meet these recommendations:

RAM Considerations

  • Absolute Minimum: 256MB RAM (Not recommended for real use).
  • Recommended Minimum: 1 GB+ RAM.
  • Production / Heavy Use: 4 GB+ RAM is strongly advised. Jenkins itself uses memory, but so do the builds and processes it spawns. More complex pipelines require more RAM.

Disk Space Needs

  • Minimum: 1 GB (Only for Jenkins itself, very basic jobs).
  • Recommended: 50 GB+ free space. Remember, Jenkins stores job configurations, build logs, artifacts, and potentially Docker images or workspace data. This can grow quickly! Fast disk I/O (like an SSD) also significantly improves performance.

CPU Recommendations

  • A modern multi-core CPU is recommended. While Jenkins itself isn’t constantly CPU-intensive, the builds it runs can be. 2+ CPU cores are a good starting point.

In short: Don’t try to run a serious Jenkins instance on a tiny virtual machine if you can avoid it. Give it some reasonable resources to work with.

Updating Your Ubuntu System (Keeping Things Fresh)

It’s always best practice to start with an up-to-date system. This ensures you have the latest security patches and package information. Open your terminal and run:

sudo apt update
sudo apt upgrade -y

The sudo apt update command refreshes your local package lists, finding out what new versions are available. sudo apt upgrade -y then downloads and installs those newer versions (-y automatically confirms the prompts).

Essential User Permissions (The Power of sudo)

You’ll need to run commands with administrative privileges to install software and modify system configurations. Ensure the user account you’re using has sudo access. Most standard installations set this up for the initial user, but if you’re using a different account, you might need to add it to the sudo group:

# Replace 'your_username' with your actual username
sudo usermod -aG sudo your_username

You might need to log out and log back in for the group change to take effect. Throughout this guide, we’ll use sudo before commands that require root privileges.

Installing Java: Jenkins’ Essential Prerequisite

Jenkins is a Java application. Without a compatible Java Runtime Environment (JRE) or Java Development Kit (JDK), it simply won’t run.

Why Jenkins Needs Java

Jenkins itself is written in Java. It runs within a Java Virtual Machine (JVM), which provides the environment for the code to execute. Therefore, installing a supported JDK is a non-negotiable first step. Jenkins currently supports Java 11 and Java 17 as the recommended versions. We’ll focus on installing OpenJDK, the free and open-source implementation of the Java Platform.

Checking for Existing Java Installations

Before installing, let’s see if Java is already present on your system. Run:

java -version

If Java is installed, you’ll see output detailing the version (e.g., openjdk version "11.0.22" or openjdk version "17.0.10"). If it says “command not found” or similar, you need to install it. If you have an older, unsupported version (like Java 8), it’s highly recommended to install Java 11 or 17 alongside or instead of it for Jenkins.

Installing the Recommended Java Version (OpenJDK 11 or 17)

We’ll install OpenJDK 17, as it’s a recent Long-Term Support (LTS) version. If you prefer Java 11, simply replace openjdk-17-jdk with openjdk-11-jdk in the command below.

Command Line Steps for Installation

  1. Update package index (again, just to be sure):
    sudo apt update
  2. Install OpenJDK 17:
    sudo apt install openjdk-17-jdk -y

    This command downloads and installs the JDK package and its dependencies.

Verifying Your Java Installation

Once the installation is complete, verify it by running the version check again:

java -version

This time, you should see output confirming that OpenJDK 17 (or 11, if you chose that) is installed and ready to go. Great! Java is sorted.

Adding the Jenkins Repository: Getting the Official Package

While you could download and run the Jenkins .war file directly, the recommended way to install and manage Jenkins on Debian-based systems like Ubuntu is by using the official Jenkins project-maintained package repository.

Why Use the Official Jenkins Repository? (Stability & Updates)

Using the official repository offers several advantages:

  • Easy Installation: Uses the standard apt package manager.
  • Simple Updates: Updating Jenkins becomes as easy as running sudo apt update && sudo apt upgrade.
  • Service Management: The package automatically sets up Jenkins to run as a system service.
  • Official Support: You’re getting the package directly from the Jenkins project.

Importing the Jenkins GPG Key (Security First!)

Before your system trusts the Jenkins repository, you need to add its GPG key. This key verifies that the packages you download are genuinely from the Jenkins project and haven’t been tampered with.

curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \
  /usr/share/keyrings/jenkins-keyring.asc > /dev/null

This command downloads the key using curl, and then sudo tee writes it to a designated keyring file (/usr/share/keyrings/jenkins-keyring.asc). We use the -stable URL here to get the Long-Term Support (LTS) release, which is recommended for stability. If you prefer the latest features (potentially less stable), you can use the debian path instead of debian-stable.

Adding the Jenkins Software Repository to Your System

Now, tell your system where to find the Jenkins packages by adding the repository configuration:

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

This command creates a new list file (/etc/apt/sources.list.d/jenkins.list) containing the repository URL and specifies that packages from this repo should be verified using the key we just added.

Updating Your Package List Again

With the new repository added, we need to update the apt package list one more time so it becomes aware of the packages available from the Jenkins repository (specifically, the jenkins package):

sudo apt update

You should see lines in the output referencing https://pkg.jenkins.io.

Installing Jenkins: The Main Event!

The groundwork is done! Java is installed, and your system knows where to find the official Jenkins package. Installing Jenkins is now incredibly straightforward.

The Simple Installation Command (apt install jenkins)

Execute the following command in your terminal:

sudo apt install jenkins -y

This command tells the package manager to find the jenkins package (which it now knows about thanks to the repository we added) and install it, along with any necessary dependencies.

What Happens During Installation?

Behind the scenes, this command does several things:

  • Downloads the Jenkins package.
  • Installs the Jenkins software, typically into /usr/share/jenkins/.
  • Creates a dedicated jenkins user and group to run the service securely.
  • Sets up Jenkins to run as a systemd service.
  • Creates configuration files (e.g., /etc/default/jenkins).
  • Sets up necessary directories (e.g., /var/lib/jenkins for Jenkins home, /var/log/jenkins for logs).

The installation might take a minute or two depending on your system’s speed and internet connection.

Managing the Jenkins Service: Taking Control

The package installation automatically sets up Jenkins as a system service, managed by systemd (the standard service manager on modern Ubuntu). Let’s ensure it’s running and enable it to start automatically on boot.

Starting the Jenkins Service

Although the installation process usually starts the service automatically, it’s good practice to ensure it’s running or start it manually if needed:

sudo systemctl start jenkins

This command explicitly tells systemd to start the Jenkins service.

Checking the Jenkins Service Status (Is it Running?)

This is a crucial step to verify the installation was successful and Jenkins is actually running.

sudo systemctl status jenkins

You should see output indicating the service is active (running). Look for green text and confirmation messages. It will also show the process ID (PID) and recent log entries.

If the status shows inactive (dead) or failed, something went wrong. Check the logs mentioned in the status output or use journalctl -u jenkins for more details. Common initial issues relate to Java configuration or port conflicts.

Enabling Jenkins to Start on Boot (Set it and Forget it)

You almost certainly want Jenkins to start automatically whenever your server reboots. To enable this:

sudo systemctl enable jenkins

This command creates the necessary symbolic links so that systemd automatically starts the Jenkins service during the system boot sequence. You won’t need to manually start it after every reboot.

Configuring the Firewall: Allowing Access

By default, Jenkins listens on port 8080. If you’re running a firewall on your Ubuntu server (which you absolutely should be!), you need to explicitly allow incoming traffic on this port so you can access the Jenkins web interface. We’ll use UFW (Uncomplicated Firewall), which is the default firewall tool in Ubuntu.

Why Firewall Configuration is Crucial

Firewalls block unwanted network traffic, enhancing security. However, they will also block legitimate traffic (like your browser trying to connect to Jenkins) unless you create rules to allow it. Without opening port 8080, you won’t be able to reach the Jenkins setup page.

Allowing Jenkins Through UFW (Uncomplicated Firewall)

First, ensure UFW is enabled. If you haven’t configured it before, you might enable it with sudo ufw enable (be careful if you’re connected via SSH – ensure your SSH port, usually 22, is allowed first: sudo ufw allow ssh).

Opening Port 8080

To allow traffic on port 8080 for Jenkins:

sudo ufw allow 8080/tcp

This command tells UFW to allow incoming TCP connections on port 8080. Jenkins uses TCP.

Verifying Firewall Status

Check that the rule was added correctly:

sudo ufw status

You should see output listing the allowed ports, including 8080/tcp (or just 8080) with an action of ALLOW from Anywhere.

Initial Jenkins Setup via Web Interface

With Jenkins installed, running, and accessible through the firewall, it’s time for the initial configuration via your web browser.

Accessing the Jenkins Dashboard (Your First Look!)

Open your favorite web browser and navigate to your server’s IP address or domain name, followed by port 8080:

http://your_server_ip_or_domain:8080

Replace your_server_ip_or_domain with the actual public or private IP address of your Ubuntu server or its configured domain name.

If everything is working, you’ll be greeted by the “Unlock Jenkins” page.

Unlocking Jenkins: Finding the Initial Admin Password

For security, Jenkins protects the initial setup with an automatically generated password. The setup page tells you where to find this password on your server.

Locating the Password File

The password is stored in a file on the Jenkins server. The typical location is:
/var/lib/jenkins/secrets/initialAdminPassword

Using the Command Line to Display the Password

You can easily display this password using the cat command in your server’s terminal:

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

This command will output a long alphanumeric string. Copy this entire password string.

Go back to your browser, paste the password into the “Administrator password” field, and click “Continue.”

Customizing Jenkins with Plugins (Suggested vs. Manual)

After unlocking, Jenkins will prompt you to install plugins. Plugins extend Jenkins’ functionality, allowing it to integrate with version control systems (like Git), build tools (like Maven or Gradle), notification systems, cloud providers, and much more.

You have two options:

  1. Install suggested plugins: This installs a standard set of useful plugins commonly used in many CI/CD workflows (Git, Pipeline, Workspace Cleanup, etc.). This is highly recommended for beginners.
  2. Select plugins to install: This allows you to pick and choose specific plugins. You can always add or remove plugins later.

Click “Install suggested plugins.” Jenkins will now download and install the selected plugins. This might take several minutes, depending on your internet connection and the number of plugins. You’ll see a progress screen showing the installation status of each plugin.

Creating Your First Admin User (Security Best Practice)

Once the plugins are installed, Jenkins prompts you to create the first administrative user account. Do not skip this step! Using the initial admin user unlocked with the temporary password is not secure for long-term use.

Fill in the required fields:

  • Username
  • Password (choose a strong one!)
  • Full name
  • Email address

Click “Save and Continue.”

Instance Configuration: Setting Your Jenkins URL

Finally, Jenkins will ask you to confirm the URL for your Jenkins instance. It usually detects this correctly based on how you accessed it. Ensure the URL shown is the preferred address you’ll use to access Jenkins.

Click “Save and Finish.”

You should now see a “Jenkins is ready!” page. Click “Start using Jenkins.”

Congratulations! You’ll be redirected to the main Jenkins dashboard, logged in as the admin user you just created. You have successfully installed and configured Jenkins on your Ubuntu server!

Post-Installation: What’s Next?

You’ve got Jenkins running, but the journey is just beginning. Here are a few immediate next steps:

Exploring the Jenkins Dashboard

Take some time to familiarize yourself with the Jenkins UI. Key areas include:

  • Manage Jenkins: (Left sidebar) This is where you configure system settings, manage plugins, users, nodes (agents), security, and more.
  • New Item: (Left sidebar) This is where you create new Jenkins jobs (e.g., Pipeline, Freestyle project).
  • Build Queue / Build Executor Status: (Left sidebar) Shows jobs waiting to run and currently running builds.

Basic Security Considerations (Beyond the Initial Setup)

While creating an admin user is a good start, consider these next security steps (though they are beyond the scope of this basic installation guide):

  • Configure Authentication & Authorization: Explore different security realms (like LDAP or SAML) and authorization strategies (matrix-based security) in “Manage Jenkins” -> “Configure Global Security.”
  • Set up HTTPS/SSL: Running Jenkins over plain HTTP is insecure, especially if accessible over the internet. Configure a reverse proxy (like Nginx or Apache) to handle SSL termination (HTTPS).
  • Disable unnecessary services/ports.

Running Your First Jenkins Job (A Simple Example)

Let’s create a basic “Hello World” job to see it in action:

  1. Click New Item on the left.
  2. Enter an item name (e.g., HelloWorld).
  3. Select Freestyle project and click OK.
  4. Scroll down to the Build section.
  5. Click Add build step and choose Execute shell.
  6. In the command box, type: echo "Hello Jenkins World!"
  7. Click Save.
  8. On the project page, click Build Now in the left sidebar.
  9. You’ll see a build appear in the Build History. Click the build number, then click Console Output to see the log, including your “Hello Jenkins World!” message.

You’ve just run your first automated task with Jenkins!

Troubleshooting Common Installation Issues

Even following steps carefully, you might encounter bumps. Here are a few common ones:

Jenkins Service Fails to Start

  • Check Status: Run sudo systemctl status jenkins. Look for error messages.
  • Check Logs: Use sudo journalctl -u jenkins or check /var/log/jenkins/jenkins.log for detailed errors.
  • Verify Java: Ensure the correct Java version is installed (java -version) and that Jenkins is configured to use it (check /etc/default/jenkins for JAVA_HOME if necessary, though usually auto-detected).
  • Port Conflict: Is another service already using port 8080? Use sudo ss -tulnp | grep 8080 to check. If so, you’ll need to stop the other service or change the Jenkins port (see FAQs).

Cannot Access Jenkins Web UI (Port 8080 Issues)

  • Check Service Status: Is Jenkins running? (sudo systemctl status jenkins).
  • Check Firewall: Did you allow port 8080? (sudo ufw status). Is UFW enabled?
  • Correct IP/Domain: Are you using the correct IP address or domain name for your server in the browser URL?
  • Network Issues: Can you reach the server at all (e.g., via ping your_server_ip)? Are there any network firewalls between you and the server blocking the port?

“Java Not Found” Errors

This usually indicates Jenkins can’t find a compatible Java installation.

  • Re-verify Installation: Run java -version.
  • Check PATH: Ensure the Java executable is in the system’s PATH. The OpenJDK installation usually handles this.
  • Specify JAVA_HOME (Advanced): In rare cases, you might need to explicitly set the JAVA_HOME environment variable for the jenkins user or in the /etc/default/jenkins configuration file, pointing it to your JDK installation directory (e.g., /usr/lib/jvm/java-17-openjdk-amd64).

Frequently Asked Questions (FAQs)

1. Can I install Jenkins using a different method on Ubuntu (like Docker)?

Yes, absolutely! Running Jenkins in a Docker container is a very popular alternative. It provides isolation, simplifies dependency management, and makes deployments consistent. You can find official Jenkins Docker images on Docker Hub. The installation steps differ significantly, involving pulling the image and running a container instead of using apt.

2. How do I update Jenkins after installation?

Because we installed Jenkins using the official repository via apt, updating is straightforward. Simply run the standard system update commands in your terminal:

sudo apt update
sudo apt upgrade

If a new Jenkins version is available in the repository you added, apt upgrade will handle downloading and installing it, usually restarting the Jenkins service automatically. Always check the Jenkins changelog before upgrading major versions.

3. Can I change the default Jenkins port (8080)?

Yes. The default port is configured in the Jenkins systemd service file or the defaults file. The easiest way is often to edit /etc/default/jenkins. Look for the HTTP_PORT variable (it might be commented out). Uncomment it if necessary and change the value from 8080 to your desired port (e.g., HTTP_PORT=8090). After saving the file, restart the Jenkins service: sudo systemctl restart jenkins. Remember to also update your firewall rules (sudo ufw allow your_new_port/tcp) and allow the old one (sudo ufw delete allow 8080/tcp) if needed. Using standard ports below 1024 requires extra configuration or running Jenkins as root (not recommended). A reverse proxy is often a better way to expose Jenkins on standard ports like 80 or 443.

4. What’s the difference between Jenkins LTS and Weekly releases?

  • LTS (Long-Term Support): Releases are chosen every 12 weeks from the stream of weekly releases. They receive backported bug fixes and stability improvements during their support lifecycle. Recommended for production and stability-focused environments. We used the debian-stable repository for LTS.
  • Weekly: Releases contain the latest features, enhancements, and bug fixes delivered every week. Suitable for users who want the newest functionality and are comfortable with a faster release cadence, potentially encountering newer bugs. To use weekly, you’d adjust the repository URL during the setup steps (using debian instead of debian-stable).

5. How much memory does Jenkins *really* need?

While the minimum recommendation is 1GB RAM, real-world usage depends heavily on workload. Factors include: the number of concurrent builds, the complexity of pipelines (Groovy scripts in Pipelines consume memory), the number and type of plugins installed, and the size of build artifacts stored. For small teams with simple jobs, 2-4GB might suffice. For larger teams or complex pipelines (especially using Docker within Jenkins), 8GB, 16GB, or even more might be necessary for optimal performance and to avoid OutOfMemoryError issues. Monitor your Jenkins instance’s memory usage under load to determine appropriate sizing.

Marshall Anthony is a professional Linux DevOps writer with a passion for technology and innovation. With over 8 years of experience in the industry, he has become a go-to expert for anyone looking to learn more about Linux.

Related Posts