Step-by-step Guide: Installing Jenkins on a Linux EC2 Instance for Scalable CI/CD
Many developers jump into Jenkins without considering why AWS EC2 offers an ideal platform for scalable automation—let’s break down exactly how setting up Jenkins on a Linux EC2 instance gives you control, flexibility, and performance unlike traditional hosts.
Jenkins is a cornerstone for automating builds and deployments in modern DevOps workflows. Installing it efficiently on a Linux EC2 instance ensures a robust, scalable continuous integration/continuous deployment (CI/CD) pipeline tailored to cloud infrastructure needs.
In this practical how-to post, I’ll walk you through the straightforward process of installing Jenkins on a Linux-based EC2 instance (using Amazon Linux 2 as an example), enabling you to leverage AWS’s power for your automation needs.
Why Choose Jenkins on AWS EC2?
Before diving into commands, here’s why deploying Jenkins on an EC2 instance is a smart move:
- Scalability: Easily upgrade instance types, scale out with load balancers or auto-scaling groups.
- Flexibility: Full control over Jenkins environment, OS settings, plugins, and security configurations.
- Integration: Seamlessly connect with AWS services like S3, CodeCommit, Lambda from the same environment.
- Performance: Tunable resource allocations ensure optimal build speeds.
Prerequisites:
- An active AWS account with IAM permissions to create and manage EC2 instances.
- Basic familiarity with SSH and Linux shell commands.
- SSH client to connect to your EC2 instance.
Step 1: Launch a Linux EC2 Instance
- Log into the AWS Management Console.
- Navigate to EC2 > Instances > Launch Instances.
- Choose Amazon Linux 2 AMI (HVM), SSD Volume Type as the OS.
- Select an appropriate instance type (e.g.,
t3.medium
is a reasonable start for Jenkins). - Configure instance details per your network; default VPC/subnet works fine for testing.
- Add storage — the default 8 GB should suffice initially but consider increasing if you expect large pipelines.
- Configure security groups:
- Open port 22 (SSH) for your IP or CIDR block.
- Add custom TCP rule port 8080 (default Jenkins port) open to the IP(s) that will access the UI.
- Review and launch; select or create a key pair for SSH access.
Step 2: Connect to Your EC2 Instance via SSH
Once running, connect with:
ssh -i /path/to/your-key.pem ec2-user@<your-ec2-public-ip>
Replace /path/to/your-key.pem
and <your-ec2-public-ip>
accordingly.
Step 3: Update Packages and Install Java
Jenkins runs on Java, so install OpenJDK first:
sudo yum update -y
sudo amazon-linux-extras install java-openjdk11 -y
java -version
You should see something like:
openjdk version "11.0.x" ...
Step 4: Add Jenkins Repository & Install Jenkins
Import the repository’s GPG key and add it to your system:
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
Now install Jenkins with:
sudo yum install jenkins -y
This installs the latest stable Jenkins release from official sources.
Step 5: Start and Enable Jenkins Service
Start Jenkins:
sudo systemctl start jenkins
Enable it to launch on boot:
sudo systemctl enable jenkins
Check service status:
sudo systemctl status jenkins
You should see the service active (running).
Step 6: Configure Firewall/Security Group (If Needed)
If using firewalld
or iptables
inside the instance (unlikely on Amazon Linux by default), make sure port 8080 is open.
More importantly, verify your AWS security group includes inbound access on port 8080 for Jenkins UI access.
Step 7: Access Jenkins Web Interface
Open your browser and navigate to:
http://<your-ec2-public-ip>:8080/
You will be greeted with the Unlock screen asking you to enter the initial admin password.
Find this password by running:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy-paste this password into the setup page.
Step 8: Customize Your Jenkins Installation
Follow these steps on the web UI:
- Select suggested plugins (commonly used plugins are automated installed).
- Create your first admin user per prompt or skip to continue as admin.
Jenkins is now installed and ready for configuring jobs/pipelines!
Bonus Tips
Running Jenkins Behind nginx Reverse Proxy (Optional)
If you want nicer URLs or HTTPS support down the line, consider installing nginx and proxying traffic from port 80/443 to port 8080.
Example nginx config snippet:
server {
listen 80;
server_name your.domain.com;
location / {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Backing Up Your Jenkins Data
Your job configurations and pipeline history live under /var/lib/jenkins
. Regularly snapshot this directory or use plugins that help backup jobs and settings.
Scaling Up For Load
When your CI/CD demands grow, you can scale vertically by resizing your EC2 instance or horizontally by adding build agents connected via SSH or Kubernetes plugin.
Wrapping Up
You’ve just turned an Amazon Linux EC2 instance into a powerful automation hub using Jenkins! This set-up equips you with unparalleled flexibility over your CI/CD pipelines combined with AWS's scalable infrastructure.
From here, explore adding integrations like GitHub webhook triggers, Docker builds inside pipelines, or deploying directly onto ECS/EKS clusters utilizing this solid foundation.
Happy building! 🚀