How To Install Jenkins on AlmaLinux 9
Jenkins, an open-source automation server, has become an indispensable tool in the world of DevOps. It enables developers to build, test, and deploy their applications efficiently and consistently. As organizations continue to embrace continuous integration and continuous delivery (CI/CD) practices, Jenkins stands out as a versatile solution that can adapt to various environments and workflows.
AlmaLinux 9, a robust and stable Linux distribution, provides an excellent platform for hosting Jenkins. Its compatibility with Red Hat Enterprise Linux (RHEL) makes it a popular choice for enterprise-level deployments. In this comprehensive guide, we’ll walk you through the process of installing Jenkins on AlmaLinux 9, ensuring you have a solid foundation for your CI/CD pipeline.
Prerequisites
Before we dive into the installation process, let’s ensure you have everything you need to successfully set up Jenkins on AlmaLinux 9:
- A server running AlmaLinux 9 with at least 2GB of RAM and 10GB of free disk space
- Root access or a user with sudo privileges
- A stable internet connection for downloading packages
- Basic familiarity with Linux command-line operations
It’s crucial to meet these requirements to ensure a smooth installation process and optimal performance of Jenkins on your AlmaLinux 9 system.
Updating the System
Before installing any new software, it’s always a good practice to update your system. This ensures that you have the latest security patches and package versions, reducing the risk of compatibility issues.
To update your AlmaLinux 9 system, run the following command:
sudo dnf update -y
This command will fetch the latest package information and upgrade all installed packages to their newest versions. The “-y
” flag automatically answers “yes” to any prompts, streamlining the update process.
Installing Java
Jenkins requires Java to run. AlmaLinux 9 doesn’t come with Java pre-installed, so we need to set it up. We’ll use OpenJDK, an open-source implementation of the Java Platform.
First, check if Java is already installed on your system:
java -version
If Java is not installed, you’ll see a message indicating that the command is not found. In this case, proceed with the installation of OpenJDK:
sudo dnf install java-11-openjdk -y
After the installation completes, verify that Java is correctly installed by running the version check command again:
java -version
You should now see output indicating the installed Java version.
Adding Jenkins Repository
Jenkins is not available in the default AlmaLinux 9 repositories. Therefore, we need to add the official Jenkins repository to our system. This ensures we can easily install and update Jenkins using the package manager.
First, import the Jenkins repository GPG key:
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
Next, add the Jenkins repository to your system by creating a new repository file:
sudo tee /etc/yum.repos.d/jenkins.repo <<EOF
[jenkins]
name=Jenkins-stable
baseurl=http://pkg.jenkins.io/redhat-stable
gpgcheck=1
EOF
This command creates a new file named “jenkins.repo
” in the “/etc/yum.repos.d/
” directory, containing the necessary information for the package manager to locate and use the Jenkins repository.
Installing Jenkins
With the repository added, we can now proceed to install Jenkins. Run the following command to install Jenkins on your AlmaLinux 9 system:
sudo dnf install jenkins -y
This command will download and install Jenkins along with its dependencies. The installation process may take a few minutes, depending on your internet connection speed.
If you encounter any errors during the installation, double-check that you’ve correctly added the Jenkins repository and that your system is up to date. In some cases, you may need to clear the DNF cache and try again:
sudo dnf clean all
sudo dnf install jenkins -y
Configuring Firewall
By default, Jenkins runs on port 8080. We need to configure the firewall to allow incoming traffic on this port. AlmaLinux 9 uses firewalld as its default firewall management tool.
To open port 8080, run the following commands:
sudo firewall-cmd --permanent --add-port=8080/tcp
sudo firewall-cmd --reload
The first command adds a rule to allow TCP traffic on port 8080, and the second command reloads the firewall to apply the changes. If you plan to access Jenkins through a web browser on a different machine, this step is crucial for establishing connectivity.
Starting and Enabling Jenkins Service
Now that Jenkins is installed and the firewall is configured, we can start the Jenkins service and enable it to start automatically on system boot.
To start the Jenkins service, use this command:
sudo systemctl start jenkins
To enable Jenkins to start on boot, run:
sudo systemctl enable jenkins
You can verify that Jenkins is running by checking its status:
sudo systemctl status jenkins
If everything is set up correctly, you should see output indicating that the Jenkins service is active and running.
Initial Jenkins Setup
With Jenkins installed and running, it’s time to perform the initial setup through the web interface. Open a web browser and navigate to:
http://your_server_ip:8080
Replace “your_server_ip
” with the actual IP address or domain name of your AlmaLinux 9 server.
You’ll be presented with a screen asking for the initial admin password. To retrieve this password, run the following command:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy the output and paste it into the web interface to unlock Jenkins.
Next, you’ll be prompted to install plugins. For most users, the “Install suggested plugins” option is recommended. This will set up commonly used plugins that enhance Jenkins’ functionality.
After the plugins are installed, you’ll be asked to create the first admin user. Fill in the required information, including username, password, full name, and email address. This account will have full access to Jenkins, so make sure to use a strong, unique password.
Basic Jenkins Configuration
Once you’ve completed the initial setup, you’ll be taken to the Jenkins dashboard. From here, you can start configuring Jenkins to suit your needs. Here are some basic configurations to consider:
Global Settings
Navigate to “Manage Jenkins” > “Configure System” to access global settings. Here you can set up things like the number of executors, system message, and environment variables.
Security Options
Under “Manage Jenkins” > “Configure Global Security”, you can set up authentication methods, authorization strategies, and other security-related options. It’s crucial to review and configure these settings to ensure your Jenkins instance is secure.
Email Notifications
To set up email notifications, go to “Manage Jenkins” > “Configure System” and scroll down to the “E-mail Notification” section. Enter your SMTP server details to enable Jenkins to send email alerts.
Creating Your First Jenkins Job
Jenkins uses “jobs” to define and manage tasks in your CI/CD pipeline. Let’s create a simple job to get you started:
- From the Jenkins dashboard, click on “New Item”.
- Enter a name for your job and select “Freestyle project”.
- Click “OK” to create the job.
- In the job configuration page, scroll down to the “Build” section.
- Click “Add build step” and select “Execute shell”.
- In the command box, enter a simple command like
echo "Hello, Jenkins!"
- Click “Save” to finish creating the job.
To run the job, go back to the job’s main page and click “Build Now”. You can monitor the build progress and view the console output to see the results of your command.
Troubleshooting Common Issues
While setting up Jenkins on AlmaLinux 9, you might encounter some common issues. Here are a few troubleshooting tips:
Jenkins Fails to Start
If Jenkins doesn’t start, check the system logs for error messages:
sudo journalctl -u jenkins
Common causes include insufficient permissions or port conflicts.
Unable to Access Web Interface
If you can’t access the Jenkins web interface, verify that the firewall is correctly configured and that Jenkins is running. You can also try restarting the Jenkins service:
sudo systemctl restart jenkins
Plugin Installation Problems
If you’re having trouble installing plugins, it could be due to network issues or incompatible versions. Try updating Jenkins to the latest version and clearing the plugin cache:
sudo rm -rf /var/lib/jenkins/plugins
Then restart Jenkins and attempt the plugin installation again.
Congratulations! You have successfully installed Jenkins. Thanks for using this tutorial for installing Jenkins on your AlmaLinux 9 system. For additional help or useful information, we recommend you check the official Jenkins website.