Install Jenkins on AWS EC2
A comprehensive, step-by-step guide to setting up a production-ready CI/CD server. This covers installing the required Java runtime, configuring the Jenkins repository, unlocking the administrative dashboard, and setting up a reverse proxy.
0 System Requirements
Ensure your EC2 instance meets the minimum requirements for stable performance.
Instance Type
t2.small or larger
OS
Ubuntu 24.04 / 22.04
Java
OpenJDK 17 or 21
Storage
10GB+ Free Space
1 Prerequisites & Security Groups
| Type | Port | Source | Reason |
|---|---|---|---|
| SSH | 22 | My IP (Recommended) | Terminal access |
| Custom TCP | 8080 | Anywhere (0.0.0.0/0) | Jenkins Dashboard (Default) |
| HTTP | 80 | Anywhere (0.0.0.0/0) | Nginx Reverse Proxy (Optional) |
Important Note
By default, Jenkins runs on port 8080. You must open this port in your AWS Security Group to access the dashboard unless you configure a reverse proxy immediately.
2 Install Java (OpenJDK)
Jenkins is a Java-based application. We will install OpenJDK 17, which is the current Long Term Support (LTS) version recommended for Jenkins.
# Update package list
sudo apt update
# Install OpenJDK 17
sudo apt install fontconfig openjdk-17-jre -y
# Verify Installation
java -version
3 Install Jenkins
We will use the official Debian package repository to install the LTS (Long Term Support) version of Jenkins.
# 1. Add Jenkins GPG Key
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
# 2. Add Jenkins Repository
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/null
# 3. Update & Install
sudo apt-get update
sudo apt-get install jenkins -y
4 Start & Enable Service
Start the Jenkins service and enable it to launch automatically on system reboot.
# Enable (Auto-start on boot)
sudo systemctl enable jenkins
# Start the service immediately
sudo systemctl start jenkins
# Check status (Should say 'active (running)')
sudo systemctl status jenkins
5. Unlock Jenkins (Admin)
When you first access Jenkins at http://your-ec2-ip:8080, it will ask for an
Administrator password. This password is stored in a secure file on the server.
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Next Steps in Browser:
- Copy the long alphanumeric password from the terminal.
- Paste it into the Jenkins "Administrator password" field.
- Click Install suggested plugins.
- Create your first Admin User.
6 Nginx Reverse Proxy (Optional)
If you want to access Jenkins via http://your-ip (Port 80) instead of adding
:8080, configure Nginx as a reverse proxy.
# Install Nginx
sudo apt install nginx -y
# Open Config
sudo nano /etc/nginx/sites-available/default
server {
listen 80;
server_name _;
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;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
sudo systemctl restart nginx