
Mastering Jenkins: Your Ultimate Guide to Installation and Setup on Linux
In the world of modern software development, automation is king. The ability to automatically build, test, and deploy applications is no longer a luxury—it’s a necessity for efficient and reliable workflows. At the heart of this revolution is Jenkins, a powerful, open-source automation server that has become the industry standard for implementing Continuous Integration and Continuous Delivery (CI/CD) pipelines.
This comprehensive guide will walk you through the entire process of installing, configuring, and securing Jenkins on a Linux server. Whether you’re a seasoned DevOps engineer or a developer looking to streamline your workflow, you’ll find everything you need to get a robust Jenkins instance up and running.
Prerequisites: What You’ll Need
Before diving into the installation, ensure you have the following prerequisites in place:
- A Linux server (this guide covers Debian-based systems like Ubuntu and RHEL-based systems like CentOS/Fedora).
- Sudo or root privileges to execute administrative commands.
- A minimum of 1 GB of RAM and 50 GB of drive space is recommended for a production environment.
- Java Development Kit (JDK) installed. Jenkins is a Java application and requires a compatible JDK to run.
Step 1: Installing Java
If you don’t already have Java installed, it’s the first component you need to set up. We recommend using OpenJDK, a free and open-source implementation.
For Debian/Ubuntu:
Open your terminal and run the following commands to install OpenJDK 11:
sudo apt update
sudo apt install openjdk-11-jdk
For RHEL/CentOS/Fedora:
Use the yum or dnf package manager:
sudo yum install java-11-openjdk-devel
After installation, verify that Java is correctly installed by checking its version:
java -version
Step 2: Installing Jenkins
With Java in place, you can now install Jenkins. The process involves adding the official Jenkins repository to your system to ensure you receive stable updates.
Installation on Debian/Ubuntu
Add the Jenkins GPG Key: First, import the repository key to validate the packages.
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \ /usr/share/keyrings/jenkins-keyring.asc > /dev/nullAdd the Jenkins Repository: Next, add the Jenkins APT repository to your system’s sources.
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/nullInstall Jenkins: Finally, update your package index and install Jenkins.
bash
sudo apt-get update
sudo apt-get install jenkins
Installation on RHEL/CentOS/Fedora
Add the Jenkins Repository: Use the following command to add the repository.
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repoImport the GPG Key: Import the key to ensure the software’s authenticity.
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.keyInstall Jenkins: Now you can install Jenkins using
yumordnf.
bash
sudo yum install jenkins
Step 3: Managing the Jenkins Service
Once the installation is complete, the Jenkins service needs to be started and enabled to run on boot.
Use the systemctl command to manage the service:
- Start Jenkins:
bash
sudo systemctl start jenkins
- Enable Jenkins to start on boot:
bash
sudo systemctl enable jenkins
- Check the status of the Jenkins service:
bash
sudo systemctl status jenkins
If the service is active and running, you’re ready for the initial configuration.
Step 4: Initial Jenkins Configuration
With Jenkins running, the next phase is setting it up through its web interface.
Configure Your Firewall: Jenkins runs on port 8080 by default. You need to open this port in your firewall to access the web interface from another computer.
- For
ufw(common on Ubuntu):sudo ufw allow 8080 - For
firewalld(common on CentOS):sudo firewall-cmd --permanent --zone=public --add-port=8080/tcpfollowed bysudo firewall-cmd --reload
- For
Unlock Jenkins: Open your web browser and navigate to
http://your_server_ip:8080. You will be greeted by an “Unlock Jenkins” screen, which requires an initial administrator password.To find this password, run the following command in your terminal:
sudo cat /var/lib/jenkins/secrets/initialAdminPasswordCopy the alphanumeric string from the terminal, paste it into the password field in your browser, and click “Continue.”
Install Recommended Plugins: On the next screen, you’ll be asked to customize Jenkins by installing plugins. For most users, the best option is to select “Install suggested plugins.” This will install a standard suite of plugins that cover building, reporting, SCM integrations, and more.
Create Your First Admin User: After the plugins are installed, you will be prompted to create your first administrative user. It is a critical security practice to create a dedicated admin user rather than continuing to use the default
adminaccount. Fill out the form with your desired username, password, and email address.
Once you complete this step, your Jenkins instance is ready to use!
Essential Jenkins Security Tips
A default Jenkins installation is not secure. To protect your automation server in a production environment, consider these actionable security measures:
- Configure a Reverse Proxy: Place Jenkins behind a reverse proxy like Nginx or Apache. This allows you to enable SSL/TLS (HTTPS) to encrypt traffic, offload authentication, and hide the default Jenkins port from the public internet.
- Use Role-Based Access Control (RBAC): Install the Role-based Authorization Strategy plugin. This lets you create granular permissions, ensuring users and teams only have access to the jobs and settings they need.
- Keep Jenkins and Plugins Updated: Regularly check for updates to the Jenkins core and all installed plugins. Outdated plugins are a primary source of security vulnerabilities.
- Disable or Secure the Script Console: The Jenkins Script Console provides powerful administrative access. Limit who can use it and consider disabling it if it’s not needed for your daily operations.
- Configure Global Security Settings: In the “Manage Jenkins” > “Configure Global Security” section, you can disable sign-ups, set security realms, and configure authorization strategies to harden your instance.
By following these steps, you have not only installed Jenkins but have also established a secure and stable foundation for all your future CI/CD pipelines. You are now ready to start creating jobs, connecting to source code repositories, and automating your development workflow.
Source: https://www.fosslinux.com/128502/how-to-install-and-use-jenkins-on-linux.htm


