Open In App

Install Jenkins on Amazon EC2: Step-by-Step Guide

Last Updated : 23 Apr, 2024
Like Article

Jenkins configuration in the EC2 instance on the Amazon Web Service Platform includes all steps in detail, which helps the user easily set up your Jenkins tools on the EC2 instance for continuous integration and continuous development. Nowadays, Jenkins has become a more popular tool as compared to others, and it is open source. It is free, and it is lightweight. Jenkins using the 8080 port. Jenkins code is available for everyone to contribute and add more features to this tool. It has a strong community and it has a number of plugins to do any type of work related to continuous integration and continuous development.


Installing Jenkins on Amazon EC2 | Step-By-Step Guide

Below are the steps to guide the launch of an EC2 instance and install Jenkins on AWS EC2:

1. Launching an Amazon EC2 instance

Launch a virtual server in the Amazon Web Services (AWS) Elastic Compute Cloud (EC2) service and configure it with Jenkins, enabling you to deploy and run applications on scalable compute capacity within the AWS cloud infrastructure while utilizing Jenkins for continuous integration and deployment workflows.

Step 1: Open the AWS console. Click on the EC2 Service.

Select  EC2


Step 2: Click on the Launch Instance button

Launch instance


Step 3: Type the Instance name – Ubuntu. Select the AMI – Ubuntu

Select OS and AMI


2. Creating a key pair

How To A Create A Key Pairs In AWS-EC2 ? |Complete Tutorial – Read.

In the following step 4 we are selecting the existing key pair.

Step 1: Select the Instance type – t2.micro.Create or choose the existing Key pair – linux1

Select instance type and Keypair


3. Creating a security group

What is Security Group in AWS and How To Create it? – Read.

In the following step we are selecting the existing security group.

Step 1: Create the security group or choose the existing security group. Open the Port. Confirm that port 8080 is open for traffic in your security groups. Jenkins uses this port by default.

  • 8080 – Jenkins
  • 80 – HTTP
  • 43 – HTTP
Select the SG


Step 2: Click on the Launch Instance Button

Launch instance


Connecting to your Linux instance

Establish a secure shell (SSH) connection to your AWS EC2 instance, allowing remote access to the server’s command-line interface for configuration, and management.

1. Using SSH to connect to your instance

Following steps to connect the VM using the ssh

Step 1: Let us SSH onto the Amazon Linux instance where Jenkins is being installed to do some things first. Open the terminal and type:

ssh -i <your_key>.pem ec2-user@<your_amazon_linux_instance_ip>

Step 2: Type the command for Root access

 sudo su -
Change to root user


Downloading and installing Jenkins

1. Install java on vm

Step 1: To ensure your system is up to date, open a terminal window and execute the following command:

apt-get update -y
Update instance


Step 2: To install Java, which is a prerequisite for Jenkins, you can use the following command in your terminal:

apt install openjdk-11-jre
Install java


Step 3: Verify the version of java by executing the following command.

 java -version
Check java version


2. Downloading Jenkins

Step 1: Below command is used for downloading and saving the Jenkins repository key to a keyring file named jenkins-keyring.asc.

curl -fsSL | sudo tee \ /usr/share/keyrings/jenkins-keyring.asc > /dev/null
Download plugins


Step 2: After making the repository URL into a file named jenkins.list in the /etc/apt/sources.list.d/ directory, the bellow command puts the Jenkins repository to the list of package sources.

echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \ binary/ | sudo tee \  /etc/apt/sources.list.d/jenkins.list > /dev/null
Install plugin


Step 3: Update the packages again using the below command.

apt-get update -y
Update instance


Installing and configuring Jenkins

Deploy and configure the Jenkins automation server on your AWS EC2 instance.

Step 1: The below command to installs Jenkins on your system using the apt package manager. The -y flag automatically confirms all prompts during the installation process, ensuring seamless installation without manual intervention.

sudo apt install jenkins -y

Install Jenkins

Step 2: The below commands enable and checks the status of the Jenkins service using systemctl. It provides information about whether Jenkins is running, stopped, or encountering any issues.

sudo systemctl enable jenkins
sudo systemctl status Jenkins

Check Jenkins status

4. Configuring Jenkins

Access the Jenkins web interface using the instance’s public IP address and port number to begin configuring and managing your Jenkins server and automation pipelines.

Step 1: Obtain Initial Admin Password.

After accessing Jenkins through your browser via “HTTP://<instance-ip>:8080”, you’ll be prompted to provide the initial admin password. This password is located in the file “/var/lib/jenkins/secrets/initialAdminPassword”. Copy the password from this file and paste it into the command shell prompt. Subsequently, you’ll receive a unique code for Jenkins initialization.

Accesses Jenkins from browserGet the password

 Step 2: Set Jenkins Administrator Password.

Once you’ve obtained the initial admin password from Step 1, paste it into the prompt labeled “Administrator password” in the Jenkins web interface. This step enables you to authenticate as the administrator and proceed with Jenkins setup and configuration.

Pate the Jenkins password

Step 3: Create the First Admin User.

In this step, you will create the first admin user for your system, granting initial administrative privileges to manage and configure the platform.


Step 4: Install Suggested Plugins.

After setting up the administrator password, click on the “Install suggested plugins” button in the Jenkins web interface. This action initiates the installation of the recommended plugins, which are essential for Jenkins functionality and features.

Install suggested plugins

Step 5: Jenkins Setup Completion.

With the installation and configuration completed, Jenkins is now ready for use. Navigate to the Jenkins dashboard and click on “New Item” to create a new job. From here, you can begin configuring and running your automated build and deployment pipelines.

Create first job

Deleting your EC2 instance

  • Navigate to the “Instances” section in the left-hand navigation bar of the Amazon EC2 console.
  • Locate the instance you want to terminate and select it.

For better guidance to terminate instance refer this link.

Configure Jenkins in EC2 – FAQ’s

How to deploy Jenkins on AWS EC2?

Deploy Jenkins on AWS EC2 by launching an EC2 instance, installing Jenkins using the package manager or Docker, and accessing it via the instance’s public IP address.

How to install Jenkins in EC2 instance Ubuntu?

To install Jenkins on an EC2 instance running Ubuntu, first, update the package index using sudo apt update. Then, install Java Development Kit (JDK) with sudo apt install default-jdk, add the Jenkins repository key with wget -q -O - | sudo apt-key add -, add the Jenkins repository with sudo sh -c 'echo deb binary/ > /etc/apt/sources.list.d/jenkins.list', update the package index again with sudo apt update, and finally install Jenkins with sudo apt install jenkins.

How to setup Jenkins on remote server?

To set up Jenkins on a remote server, first, ensure Java is installed. Then, download and install Jenkins on the server. Finally, configure Jenkins through its web interface to complete the setup.

How do I start Jenkins on Linux?

To start Jenkins on Linux, first, navigate to the Jenkins installation directory. Then, run the command “./ start” to initiate Jenkins. Finally, access Jenkins through your web browser at “http://localhost:8080.

How do I manually deploy in Jenkins?

To manually deploy in Jenkins, first, create a new Jenkins job. Then, configure the job to execute the deployment steps, such as copying files or running scripts. Finally, trigger the job manually or schedule it as needed.

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads