Installing and Configuring Jenkins: A Step-by-Step Guide
Before you can automate your software delivery pipelines, you must build a solid foundation. Installing and configuring Jenkins correctly is the first critical step toward establishing a reliable Continuous Integration and Continuous Deployment (CI/CD) environment. Because Jenkins is a Java-based application, its installation process is highly portable across operating systems, but it requires careful attention to system prerequisites and security configurations.
In this guide, we will walk through the system requirements, explore multiple installation methods, navigate the post-installation setup wizard, and review production-grade configuration practices.
System Requirements and Prerequisites
To run Jenkins efficiently, your host machine must meet specific hardware and software criteria. While Jenkins can run on minimal resources for learning purposes, production environments demand more robust provisioning.
Hardware Requirements
- Minimum for Testing: 256 MB of RAM, 10 GB of drive space.
- Recommended for Small Teams: 4 GB+ of RAM, 50 GB+ of drive space.
- Storage Type: Solid State Drives (SSD) are highly recommended because Jenkins performs frequent read/write operations on build logs and workspace files.
Software Prerequisites: The Java Runtime
Jenkins is written in Java and requires a Java Runtime Environment (JRE) or Java Development Kit (JDK) to execute. It is crucial to match the Jenkins version with a compatible Java version.
- Java 11 or Java 17: Modern versions of Jenkins require LTS (Long-Term Support) versions of Java. Java 8 is no longer supported by recent Jenkins releases.
- Java Distribution: You can use OpenJDK, Eclipse Temurin, or Amazon Corretto.
Jenkins Installation Workflow
The following diagram outlines the logical flow of setting up a new Jenkins instance, from verifying prerequisites to accessing the dashboard:
+---------------------------------------+
| Verify Java Installation (11 or 17) |
+---------------------------------------+
|
v
+---------------------------------------+
| Download Jenkins (WAR / Docker / OS) |
+---------------------------------------+
|
v
+---------------------------------------+
| Start the Jenkins Service |
+---------------------------------------+
|
v
+---------------------------------------+
| Retrieve Initial Admin Password File |
+---------------------------------------+
|
v
+---------------------------------------+
| Install Recommended Plugins via UI |
+---------------------------------------+
|
v
+---------------------------------------+
| Create Admin User & Set Instance URL |
+---------------------------------------+
Step-by-Step Installation Methods
Depending on your infrastructure, you can install Jenkins using several methods. We will focus on the two most popular and platform-independent approaches: running the standalone Web Archive (WAR) file and using Docker.
Method 1: Running Jenkins via Standalone WAR File
The Web Archive (WAR) file is the most straightforward way to run Jenkins. It is ideal for local development, testing, and systems where containerization is not available.
First, verify that Java is installed and configured in your system path by executing the following command in your terminal:
java -version
Next, download the latest Jenkins LTS WAR file from the official distribution repository. Once downloaded, navigate to the directory containing the file and execute the following command to launch Jenkins:
java -jar jenkins.war --httpPort=8080
Jenkins will begin extracting its web application resources and initializing its home directory. Keep the terminal window open; you will see the startup logs, which include a generated security token needed for the first login.
Method 2: Running Jenkins via Docker
For modern DevOps workflows, running Jenkins inside a Docker container is the preferred approach. It isolates the Jenkins environment from the host operating system and simplifies upgrades.
To run Jenkins with persistent storage and access to the host's network, execute the following Docker command:
docker run -d -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home --name jenkins-local jenkins/jenkins:lts
Let's break down this command:
- -d: Runs the container in detached mode (in the background).
- -p 8080:8080: Maps port 8080 of the container to port 8080 of your host machine. This is where you access the Jenkins web interface.
- -p 50000:50000: Maps port 50000 for inbound agent connections. This is essential when connecting distributed build executors to your controller.
- -v jenkins_home:/var/jenkins_home: Mounts a named Docker volume to persist all build configurations, job histories, and plugin installations even if the container is restarted or deleted.
- jenkins/jenkins:lts: Specifies the official Long-Term Support image maintained by the Jenkins community.
The Post-Installation Setup Wizard
Once your Jenkins instance is running, open your web browser and navigate to http://localhost:8080. You will be greeted by the Jenkins setup wizard, which guides you through securing and customizing your installation.
Step 1: Unlocking Jenkins
To prevent unauthorized access during setup, Jenkins generates a unique, temporary administrator password. You must retrieve this password to unlock the console.
- If running via the WAR file, look at the console output. You will see a long alphanumeric string enclosed in a box.
- If running via Docker, run
docker logs jenkins-localto view the terminal output. - Alternatively, you can read the password directly from the file system. The path is typically:
/var/jenkins_home/secrets/initialAdminPassword(or the equivalent location inside your custom Jenkins home directory).
Copy this password, paste it into the "Administrator password" field, and click "Continue".
Step 2: Installing Plugins
Jenkins is highly modular. On the customization screen, you are presented with two options:
- Install suggested plugins: This option is highly recommended for beginners. It automatically installs essential plugins for Git integration, pipeline creation, email notifications, and user management.
- Select plugins to install: This allows you to customize your footprint from day one. Use this option only if you have specific security constraints or minimal resource requirements.
Select "Install suggested plugins" and wait for the installation process to complete. This may take a few minutes depending on your internet connection speed.
Step 3: Creating the First Admin User
After the plugins are installed, Jenkins will prompt you to create an administrator account. While you can skip this step and continue using the temporary admin password, it is highly recommended to set up a dedicated admin account immediately.
Fill in the username, password, full name, and email address. Ensure you store these credentials securely.
Step 4: Instance Configuration
The final screen asks you to confirm the Jenkins URL. This URL is used to configure webhooks from source control management tools (like GitHub or GitLab) and to generate links in notification emails. If you are running locally, http://localhost:8080/ is sufficient. For production environments, this should be configured with your official domain name (e.g., https://jenkins.company.com/).
Real-World Use Cases
How do teams manage Jenkins installations in the real world? Here are two common patterns:
- The Hybrid Cloud Setup: Organizations run the Jenkins controller on a small, secure VM inside a private subnet. They configure the controller to dynamically spin up ephemeral build agents in AWS, Azure, or Kubernetes clusters when a build is triggered. This keeps the installation lightweight and cost-effective.
- Configuration as Code (JCasC): To avoid configuring Jenkins manually through the UI, modern operations teams use the Jenkins Configuration as Code plugin. This allows them to define system configurations, credentials, and tool paths in a single YAML file, ensuring that the entire Jenkins server can be destroyed and recreated in minutes.
Common Installation Mistakes to Avoid
- Running Jenkins as Root: Never run the Jenkins process or container as the root user in a production environment. If a build script is compromised, it could gain full access to your host system. Always run Jenkins under a dedicated, unprivileged
jenkinsuser account. - Ignoring Backup Strategies: All configurations, job setups, and build histories are stored in the
JENKINS_HOMEdirectory. Failing to back up this directory regularly can lead to catastrophic data loss. Ensure you have automated backups of this folder. - Port Conflicts: Port 8080 is commonly used by other web servers and application containers (like Apache Tomcat). If Jenkins fails to start, check your logs for a "BindException" or "Address already in use" error, and change the port using the
--httpPortparameter.
Interview Notes and Quick Reference
- What is the purpose of the JENKINS_HOME directory? It is the most important directory in Jenkins. It contains all system configurations, plugin files, build jobs, workspaces, and user credentials. Moving or backing up this directory effectively backs up your entire Jenkins instance.
- How do you change the default port of a Jenkins WAR installation? You append the
--httpPortflag to your startup command, for example:java -jar jenkins.war --httpPort=9090. - What is the difference between the LTS and Weekly release lines? The Long-Term Support (LTS) release is chosen every 12 weeks and is thoroughly tested for stability, making it ideal for production environments. The Weekly release contains the latest features and bug fixes but may be less stable.
Summary
Installing and configuring Jenkins involves verifying your Java environment, running the application through a WAR file or Docker container, and completing the post-installation setup wizard. By securing your administrative credentials, installing the recommended plugins, and understanding the significance of the JENKINS_HOME directory, you lay a secure and stable foundation for your CI/CD pipelines. In our next topic, we will explore the Jenkins dashboard, user management, and global tool configurations.