Jenkins Curriculum
On this page
- Install Linux
- 1. Preparing the AWS Infrastructure (The Foundation)
- A. Choosing the Right Instance Type (The "Hardware" Tax)
- B. Configuring the AWS Security Group
- C. EBS Storage (gp3)
- 2. The Foundation: Installing the Java Runtime (JDK)
- Why the version matters
- Step-by-Step Installation on Ubuntu:
- Step-by-Step Installation on Amazon Linux 2 (AL2):
- 3. The Installation: Adding the Jenkins Repository
- The Ubuntu/Debian Method:
- The Amazon Linux / RHEL Method:
- 4. Starting and Enabling the Jenkins Service
- Commands for the Terminal:
- Troubleshooting a "Failed" Status:
- 5. Post-Installation: Unlocking the Gate
- How to find the Secret Code:
- 6. Senior Troubleshooting: The "Pro" Checklist
- A. The "Java 8" Ghost
- B. Changing the Default Port
- C. The "Out of Memory" (OOM) Killer
- Summary
Install Linux
Imagine you have just been appointed as the Lead DevOps Engineer for a global financial institution. Your first mission is to build the central nervous system of the company's software delivery: the Jenkins server. This isn't just a "box in the corner" running a few scripts. This is a mission-critical piece of infrastructure that will manage the code for thousands of banking applications.
If this server is slow, the entire company's release cycle grinds to a halt. If it's insecure, hackers could gain access to the production environment and manipulate financial data. If it crashes, 2,000 developers are suddenly blocked from doing their jobs.
In this file, we are going to go into absolute, extreme depth on how to install Jenkins on Linux. We will focus on the two most common distributions used in the enterprise world: Ubuntu 22.04 LTS and Amazon Linux 2/2023. We won't just give you a "checklist" of commands. We will explore the architectural "Why" behind every decision—from choosing the right AWS instance type to configuring the underlying Java Virtual Machine (JVM) for maximum performance.
1. Preparing the AWS Infrastructure (The Foundation)
Before you ever run a sudo apt install command, you must prepare the "Terrain" where your server will sit. In a professional AWS environment, this is a multi-step process that involves compute, storage, and networking.
A. Choosing the Right Instance Type (The "Hardware" Tax)
Jenkins is a Java application. Java applications are notorious for being "RAM-Hungry." Furthermore, Jenkins doesn't just "sit there"; it performs heavy tasks like compiling Java code, zipping files, and running security scans.
Senior Rule: Never launch a production Jenkins server on anything less than a t3.medium. If you do, the Linux kernel will eventually "kill" the Jenkins process to save the OS from crashing (this is called an OOM - Out of Memory event).
B. Configuring the AWS Security Group
Your Jenkins server is a "High Value Target" for hackers. You must protect it with a layered defense.
- Port 22 (SSH): Allow ONLY from your specific IP or your company's VPN CIDR.
- Port 8080 (Web UI): This is the default Jenkins port. Allow from your office or VPN.
- Port 443 (HTTPS): In production, you will use an SSL certificate. This is the standard entrance.
- Port 50000 (JNLP): Used for Agents to talk to the Controller. This should NEVER be open to the internet. Open it only to the CIDR of your VPC.
C. EBS Storage (gp3)
Jenkins stores every build log, every artifact, and every plugin on disk.
- Use Amazon EBS gp3 volumes. They offer a baseline of 3,000 IOPS for free, which is essential for Jenkins because it does a lot of small file reads/writes (the "I/O" bottleneck).
2. The Foundation: Installing the Java Runtime (JDK)
Jenkins is a Java application. It requires a Java Development Kit (JDK) to run.
Why the version matters
As of early 2024, Jenkins officially supports Java 11 and Java 17.
- Java 8: Deprecated. Do not use.
- Java 21: Supported in newer versions, but many old plugins might break.
- The Senior Choice: Java 17 (LTS). It is the perfect balance of modern features and rock-solid stability.
Step-by-Step Installation on Ubuntu:
Step-by-Step Installation on Amazon Linux 2 (AL2):
3. The Installation: Adding the Jenkins Repository
We never install Jenkins by downloading a random .deb or .rpm file. Why? Because you won't get automatic security updates. Instead, we add the Official Jenkins Repository to our system.
The Ubuntu/Debian Method:
The Amazon Linux / RHEL Method:
4. Starting and Enabling the Jenkins Service
In modern Linux, services are managed by systemd. You must tell the OS that Jenkins is a "Service" that should be kept running forever.
Commands for the Terminal:
Troubleshooting a "Failed" Status:
If you see Active: failed, run this command to see the hidden error logs:
Common Errors:
Address already in use: Another program is using port 8080.Invalid Java version: You have Java 8 installed instead of 17.Permission denied: You messed up the permissions on the/var/lib/jenkinsfolder.
5. Post-Installation: Unlocking the Gate
Jenkins starts in a "Locked" mode. It creates a temporary password that only the server administrator (you) can see. This prevents "Drive-by Hackers" from taking over your new server.
How to find the Secret Code:
The output will be a 32-character string like a1b2c3d4e5f6g7h8i9j0....
- Action: Copy this string. You will need it in the next chapter when we log into the web browser.
6. Senior Troubleshooting: The "Pro" Checklist
After installing Jenkins hundreds of times, these are the "Gotchas" that save me hours of debugging.
A. The "Java 8" Ghost
If your server already had Java 8, and you installed Java 17, Jenkins might still try to use the old version.
- Fix: Use
sudo update-alternatives --config javaand choose the version pointing to Java 17.
B. Changing the Default Port
What if you want to run Jenkins on port 9090 instead of 8080?
- Ubuntu: Edit
/etc/default/jenkinsand changeHTTP_PORT=8080. - AL2/RHEL: Edit
/etc/sysconfig/jenkinsor usesystemctl edit jenkins. - Restart: You must run
sudo systemctl restart jenkinsfor the change to take effect.
C. The "Out of Memory" (OOM) Killer
If Jenkins randomly stops, check the system logs:
If you see "Out of memory," it means your EC2 instance is too small. Immediately upgrade to a t3.large.
Summary
- Linux is the King of CI/CD: 95% of production Jenkins instances run on Linux.
- Java 17 (LTS) is the engine that powers modern Jenkins.
- Security Groups and Firewalls are your first line of defense in AWS.
- Repositories ensure you get security patches automatically via
apt upgrade. - Systemd keeps your automation alive 24/7.
- Secrets: The
initialAdminPasswordis your key to the kingdom—keep it safe.
In the next file, 02-install-docker.md, we will look at how to run Jenkins as a containerized service, which is the preferred method for teams that want absolute isolation and "Portable" automation.