Install Jenkins in Ubuntu(Easily)

Step - 1 Install Java

Update your system

sudo apt update

Install java

sudo apt install openjdk-11-jre -y

Validate Installation

java -version

Install LTS jenkins

sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
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
sudo apt-get update
sudo apt-get install jenkins -y

Step -3 Start jenkins

sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins

Reboot the system

sudo reboot

Step - 4 Open port 8080 from AWS Console:

Complete Scripting for this

Make a file .sh and make it executable

vim sarthak.sh
sudo apt-get update
sudo apt-get install docker.io -y
sudo apt-get install docker-compose -y
sudo apt-get install openjdk-11-jre -y
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
  https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
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
sudo apt-get update
sudo apt-get install jenkins -y
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo cat /var/lib/jenkins/secrets/initialAdminPassword

Now make it executable

sudo chmod +x sarthak.sh
./sarthak.sh