How to Install Jenkins on Ubuntu 24.04 in AWS EC2 Instance? (A Step-by-Step Guide)

Visal Tyagi
DevOps-Guides
Published in
12 min readMay 4, 2024

Jenkins is a Continuous Integration/Continuous Delivery or Deployment (CI/CD)tool in DevOps. Jenkins is developed in the “Java” language. It implements the CI/CD workflows using pipelines or automation.

Jenkins works on “Master-Slave” architecture. This means you have to set up two nodes named “Master” & “Slave”. On the “Master” node, you will configure “Jenkins” with “Java”, while on “Slave”, you have to install “Java” only.

While “Ubuntu” is an open-source operating system based on Debian Linux that runs from the desktop or any cloud platform such as “AWS”, “Google Cloud Platform” and “Microsoft Azure”. Ubuntu is used because it is easy to use, has a better user experience & has incredible support for hardware tools.

The latest version of Ubuntu is 24.04, which is the latest version & released in “April 2024”. In this blog post, we will provide you with a detailed guide, on how to install Jenkins on Ubuntu 24.04 in AWS EC2 Instance with Master-Slave architecture.

How to Set Up Jenkins on Ubuntu in AWS EC2 Instance?
How to Set Up Jenkins on Ubuntu in AWS EC2 Instance?

To know about, how to setup Jenkins on Amazon Linux in EC2 Instance, check the Jenkins Assignment 1 given below:

A. Create Two Amazon EC2 Instances Named As Jenkins Master & Jenkins Slave

Step 1: Go to the “Services” section & search “EC2” here. Put the cursor over “EC2” & click on “Instances”.

Search EC2
Search EC2

Step 2: Click on “Launch Instance”.

Launch Instance
Launch Instance

Step 3: Choose “Name” as “Jenkins-“ in the “Name and tags” section.

Instance Name
Instance Name

Step 4: Choose “AMI” as “ubuntu”.

Ubuntu AMI
Ubuntu AMI

Step 5: Choose “Instance type” as “t2.micro”.

t2.micro instance
t2.micro instance

Step 6: Choose “key pair (login)” as “Jenkins2”.

Choose key pair
Choose key pair

Step 7: In “Network settings”, choose “Firewall (security groups)” as “Select existing security group”. While we have chosen “launch-wizard-9” as the “Common security groups”.

Network Settings
Network Settings

Step 8: In “Summary”, write “Number of Instances” as “2”. Click on “Launch Instance”.

Select the Number of Instances
Select the Number of Instances

Step 9: Two Instances will be successfully launched. Click on “Instances” in “Breadcrumbs”.

Instances
Instances

Step 10: Rename the First “Instances” as “Jenkins-Master” & second one as “Jenkins-Slave”.

Jenkins Instances
Jenkins Instances
Rename Jenkins Instances
Rename Jenkins Instances

b. Install “Jenkins” Over the Master (Jenkins-Master) Machine

Step 1: Select the “Jenkins-Master” & click on “Connect”.

Select Jenkins-Master Instance
Select Jenkins-Master Instance

Step 2: Click on “Connect” Again.

Connect the Jenkins-Master Instance
Connect the Jenkins-Master Instance

Step 3: The “Jenkins-Master” machine will be opened. Run this command to update the machine:

sudo apt-get update
Update the Machine
Update the Machine

Step 4: Now, we will install Jenkins on the “Ubuntu” machine. Run this given command:

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian/jenkins.io-2023.key

Press “Enter” from the keyboard to run this command.

Jenkins Repo will be configured on the machine.

Configure Jenkins Repo
Configure Jenkins Repo

Step 5: Now, append the Debian package repository to the server’s sources.list.

Run this given command:

echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc]" \
https://pkg.jenkins.io/debian binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null

Press “Enter” from the keyboard to run this command.

Add Debian Repository
Add Debian Repository

Step 6: Run this command to install the “java” on “Ubuntu Machine”:

sudo apt install fontconfig openjdk-17-jre

Press “Enter” from the keyboard to run this command.

Install Java Package
Install Java Package

Press “Y” to execute the “Openjdk “ installation.

Press “Y”
Press “Y”

“Java Package” will be successfully installed.

Step 7: First, update the machine & run the below-given commands to update & install the “Jenkins” over the “ubuntu machine.”:

sudo apt-get update
sudo apt-get install jenkins -y

Press “Enter” from the keyboard to run these commands.

Install Jenkins
Install Jenkins

Step 8: Now, enable the Jenkins to start the boot. Run the given command:

sudo systemctl enable jenkins

Press “Enter” from the keyboard to run this command.

Enable Jenkins
Enable Jenkins

Step 9: Now, start the “Jenkins” as a service:

sudo systemctl start jenkins

Press “Enter” from the keyboard to run this command.

Start Jenkins
Start Jenkins

Step 10: Now, check the “Jenkins service” status using this command:

sudo systemctl status jenkins

Press “Enter” from the keyboard to run this command.

Jenkins Status
Jenkins Status

Step 11: Copy the “Public IP” of “Jenkins-Master”. Put in the browser address bar with port no 8080 [http://3.15.3.52:8080/]. The “Unlock Jenkins” option will be shown.

Unlock Jenkins
Unlock Jenkins

Copy the given command.

Step 12: Put the above-given command with sudo cat in “Jenkins-Master”.

sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Press “Enter” from the keyboard.

A token will be given. Copy this token:

3bdc19525af24e9f97b0d6690e2e3b41

Copy the token
Copy the token

Step 13: Paste the given token in the “Administrator password” section. Click on “Continue”.

Paste the token
Paste the token

Step 14: Click on “Install Suggested Plugins”.

Install Suggested Plugins
Install Suggested Plugins

Step 15: Plugin will be started installing like this:

Plugin Installation Started
Plugin Installation Started

Step 16: Now, create your admin user. Put the following entries here:

Username: — admin

Password: — admin

Confirm Password: — admin

Create Admin User
Create Admin User

Full Name: — admin

E-mail Address: — admin@admin.com

Click on “Save and Continue”.

Save and Continue
Save and Continue

Step 17: Jenkins has been successfully installed. A configuration URL will be given. Click on “Save and Finish”.

Save and Finish
Save and Finish

Step 18: Click on “Start using Jenkins”.

Start Using Jenkins
Start Using Jenkins

Step 19: Your “Jenkins Dashboard” setup will be successfully done.

How to Set Up Jenkins on Ubuntu in AWS EC2 Instance?
Jenkins Dashboard

c. Install “Java” Over Slave (Jenkins-Slave) Machine

Step 1: Select the “Jenkins-Slave” & click on “Connect”.

Jenkins-Slave
Jenkins-Slave

Step 2: Click on “Connect” Again.

Connect Slave
Connect Slave

Step 3: The “Jenkins-Slave” machine will be opened. Run this command to update the machine:

sudo apt-get update
Update the Slave Machine
Update the Slave Machine

Step 4: Run the command to install the “java” on “Ubuntu”.

sudo apt install fontconfig openjdk-17-jre

Press “Enter” from the keyboard to run this command.

Install Java Over Slave
Install Java Over Slave

Type “Y” to install java.

Type “Y”
Type “Y”

“Java Package” will be successfully installed.

Step 5: Run this command to check the Java version:

java --version
Java Version
Java Version

d. Create Public & Private Key on “Jenkins-Master” to Add the “Slave” Machine

Step 1: First, go to the .ssh directory using this command: cd .ssh/

You will go to the “ssh” directory.

Go to .ssh directory
Go to .ssh directory

Step 2: Run this command to create “public” & “private” keys:

ssh-keygen

Press “Enter” from the keyboard & it will start generating the keys. Press “Enter” from the keyboard three times.

Your public key (id_ed25519.pub) & private key (id_ed25519) will be generated.

Generate Public and Private Keys
Generate Public and Private Keys

Step 3: Run this command to find the public key:

sudo cat id_ed25519.pub

Your “public key” content will be shown here. Copy the content of the keys.

Copy the Public Key Content
Copy the Public Key Content

e. Paste the Public Key (id_ed25519.pub) in “authorized_keys” file

Step 1: Go to the “Jenkins-Slave” machine. Run this command to go inside the ssh directory.

cd .ssh/

You will land inside the ssh directory.

.ssh directory slave
.ssh directory slave

Step 2: Do “ls” & “authorized_keys” will be displayed here in the .ssh directory.

ls
ls

Step 3: To edit the “authorized_keys”, use this command to open the authorized_keys file:

vim authorized_keys
edit authorized_keys file
edit authorized_keys file

Step 4: Paste the “id_ed25519.pub” content here.

Paste the Public Key Content
Paste the Public Key Content

Step 5: Press “ESC” from the keyboard & type this command to save & quit the “authorized_keys” file.

wq!
Save and Quit
Save and Quit

Step 6: Your “authorized_keys” file will be successfully saved.

Save authorized_keys file
Save authorized_keys file

f. Add a Node in Jenkins-Master using “Private Key”

Step 1: Click on “Manage Jenkins”.

Manage Jenkins
Manage Jenkins

Step 2: Click on “Nodes”.

Nodes
Nodes

Step 3: Click on “New Node”.

Click on New Node
Click on New Node

Step 4: Choose “Node name” as “Slave-1” & “Type” as “Permanent Agent”. Click on “Create”.

Create Node
Create Node

Step 5: Put the following entries here:

Name: Slave1

Description: This is a slave machine.

Number of executors: 1

Choose Slave Name & Description
Choose Slave Name & Description

Choose where you want to save the “Jenkins” data. We have installed Jenkins over “ubuntu”.

While choosing “label” as “slave”. Because Jenkins identifies the node using the “label” feature.

Usage will remain as it is.

Choose Label & Root Directory
Choose Label & Root Directory

Choose “Launch Method” as “Launch Agents via SSH”.

Host: — 172.31.11.164

Click on “Add” in “Credentials”.

Launch Agent Via SSH
Launch Agent Via SSH

Click on “Jenkins”.

Click Jenkins
Click Jenkins

Choose the following entries here:

Domain: — Global credentials (unrestricted)Remain as it is.

Kind: — SSH username with private key

Scope: — Global (Jenkins, nodes, items, all child items, etc)

Id & Description: — pwdless

Choose ID & Description
Choose ID & Description

Username: — ubuntu

Choose “Enter Directly” in “Private Key”.

Click on “Add”.

Click on Add
Click on Add

Paste the “Private Key” from “Master” here.

Go to “Jenkins-Master” & run this command: cat id_ed25519.

Copy the private key from here.

Copy Private Key Content
Copy Private Key Content

Go to “Jenkins” & paste the private key in the “Private Key” section.

Click on “Add”.

Add the Keys
Add the Keys

Choose “Credentials” as “ubuntu (pwdless)”.

While choosing “Host Key Verification Strategy” as “Non verifying Verification Strategy”.

Click on “Save”.

Save Credentials
Save Credentials

Step 6: Agent “Slave-1” has been successfully created in “Jenkins” using the “passwordless authentication”.

Slave 1 Node Created
Slave 1 Node Created

g. If the Private Key Method Does not Work, Use .pem Key Method

All steps remain the same as a private key, you have to add .pem key content in the private section. Most of the time, the above-given method doesn’t work.

In this method, you don’t need to add public & private keys to the authorized_keys section. Ignore the previous method, if it doesn't work.

Step 1: Click on “Manage Jenkins”.

Manage Jenkins
Manage Jenkins

Step 2: Click on “Nodes”.

Nodes
Nodes

Step 3: Click on “New Node”.

Click on New Node
Click on New Node

Step 4: Choose “Node name” as “Slave-1” & “Type” as “Permanent Agent”. Click on “Create”.

Create Node
Create Node

Step 5: Put the following entries here:

Name: Slave1

Description: This is a slave machine.

Number of executors: 1

Choose Slave Name & Description
Choose Slave Name & Description

Choose where you want to save the “Jenkins” data. We have installed Jenkins over “ubuntu”.

While choosing “label” as “slave”. Because Jenkins identifies the node using the “label” feature.

Usage will remain as it is.

Choose Label & Root Directory
Choose Label & Root Directory

Choose “Launch Method” as “Launch Agents via SSH”.

Host: — 172.31.11.164

Click on “Add” in “Credentials”.

Launch Agent Via SSH
Launch Agent Via SSH

Click on “Jenkins”.

Click Jenkins
Click Jenkins

Choose the following entries here:

Domain: — Global credentials (unrestricted)Remain as it is.

Kind: — SSH username with private key

Scope: — Global (Jenkins, nodes, items, all child items, etc)

Id & Description: — pwdlesss

Choose ID & Description
Choose ID & Description

Username: — ubuntu

Choose “Enter Directly” in “Private Key”.

Click on “Add”.

Click on Add
Click on Add

Copy the “Jenkins2.pem” content from here.

Jenkins Key
Jenkins Key

Paste the .pem key in “Enter Directly” in the “Private Key” section.

Add PEM Key
Add PEM Key

Choose “Credentials” as “ubuntu (pwdlesss)”.

While choosing “Host Key Verification Strategy” as “Non verifying Verification Strategy”.

Click on “Save”.

Save Credentials
Save Credentials

Step 6: Agent “Slave-1” has been successfully created in “Jenkins” using the “passwordless authentication”.

Slave 1 Node Created
Slave 1 Node Created

h. Verifying Node is Created or Not

Condition: If the “slave-1” is successfully “SSH” from “Jenkins-Master” then it’s verified that “Slave-1” is successfully created because “Slave-1” has the “Slave Private IP Address”.

Step 1: Go to Master and type this command: ssh slave private IP address

ssh 172.31.11.164

Press “Enter” from the keyboard.

Type “Yes” & press “Enter” from the keyboard.

Your “Jenkins Slave” has been successfully accessed from “Jenkins Master”.

ssh to slave
ssh to slave
Slave Successfully Connected
Slave Successfully Connected

More Jenkins Resources:

Integration of DevOps Tools with Jenkins — Jenkins Case Study

Add 2 Nodes in Jenkins & Made Push to Branches & Pull Content to Git Folder — Jenkins Assignment 2

Create a Pipeline When One Job Is Successful Another Job Should Be Triggered Automatically — Jenkins Assignment 3

--

--