Jenkins is a self-contained, open source automation server which can be used to automate all sorts of tasks related to building, testing, and delivering or deploying software.

Jenkins can be installed through native system packages, Docker, or even run standalone by any machine with a Java Runtime Environment (JRE) installed.

Step 1 – Install Prerequisites For Jenkins

Since Jenkins is a Java application, the first step is to install Java. For that we need to configure the ppa(Personal Package Archive) repository for Java 8 OpenJDK package. Update the package index and install the Java 8 OpenJDK package with the following commands

sudo add-apt-repository ppa:webupd8team/java 

sudo apt update 

sudo apt install openjdk-8-jdk 

Step 2 – Installing Jenkins

Import the GPG keys of the Jenkins repository using the following wget command and after that configure the repository for jenkins. Update the package index and install the Jenkins package with the following commands

wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add - 

sudo apt-add-repository "deb https://pkg.jenkins.io/debian-stable binary/"
 
sudo apt update 

sudo apt install jenkins 

Step 3 – Starting Jenkins

After installing Jenkins you need to enable jenkins service using systemctl command so on every reboot your jenkins is automatically start. You see the current status Jenkins service using “systemctl status jenkins” command.

sudo systemctl enable jenkins     // To enable the jenkins service at boot time

sudo systemctl start jenkins      // To start the jenkins

sudo systemctl status jenkins     // To see the current status of jenkins

Step 4 – Adjusting The Firewall Rules

If your ufw i.e universal firewall active, allow below port to accessible from intranet

sudo ufw allow 22 

sudo ufw allow 8080 

sudo ufw enable

sudo ufw status

Step 5 – Open Web browser And Enter “http://localhost:8080”

To set up your installation, visit “http://localhost:8080” . Jenkins default port is 8080 .

You should see the Unlock Jenkins screen, which displays the location of the initial password:

Step 6 – To Unlock Jenkins

Open the terminal, Enter following command to get the password and after that using that password you should able to login to jenkins.

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

Step 7 – Installing suggested plugins or selecting specific plugins

As a beginner you can go with the “Installing suggested plugins” option. But you know which plugins required for you then you can go with the “Select plugins to install” option. Select your required plugins and install them.

Step 8 – Jenkins User Creation

After installing all plugins you see screen for “Create First Admin User” fill the information and click on “save and continue”.

Step 9 – Jenkins URL configurations

In this screen you can configure your jenkins URL. I am going configure jenkins URL as “http://jenkins.localhost.com:8080“.

The /etc/hosts is an operating system file that translate hostnames or domain names to IP addresses.

sudo vi /etc/hosts

Add following line at bottom of file

127.0.0.1  jenkins.localhost.com

Step 10 – Jenkins Setup Is Completed

Congratulations! If you get this page then you successfully install Jenkins on bare ubuntu server.