How to Install Jenkins on Ubuntu Machine Step by Step

Are you spending a lot of time deploying code in your infrastructure and with many steps and software? Don’t worry; you are at the right place to learn about the famous open-source tool Jenkins, which helps build and deploy the code with a click of a button and has various other benefits.

In this tutorial, you will learn what is Jenkins and how can you install Jenkins on ubuntu 18.04 and setup step by step. Still Interested?

Join 46 other followers

Table of Content

  1. What is Jenkins
  2. Prerequisites
  3. How to Install Java on ubuntu 18.04 machine
  4. How to Install Jenkins on Ubuntu 18.04 LTS
  5. How to setup Jenkins on ubuntu
  6. Workflow of Jenkins and Code deployment
  7. Conclusion

What is Jenkins?

Jenkins is an open-source automated CI/CD tool where CI stands for continuous integration and CD stands for Continuous delivery. Jenkins has its own built-in Java servlet container server, which is Jetty. Jenkins can also be run in different servlet containers such as Apache tomcat or glassfish.

  • Jenkins can be deployed to the local machine or premises data center, or any cloud.
  • Jenkins takes your code, any sort of code such as python, java, or go or JS, etc., and compiles it using different compilers such as MAVEN, one of the most used compilers, and then builds your code in war or Zip format and sometimes as a docker image.
  • Jenkins deploys the code when required and integrates easily with various third-party tools.

Related: Python Flask Tutorial: All about Python flask

Prerequisites

  • Ubuntu 18.0.4 machine preferably; if you don’t have any machine, you can create an ec2 instance on the AWS account.
  • It is recommended to have 4GB of RAM
  • At least 5GB of drive space

You may incur a small charge for creating an EC2 instance on Amazon Managed Web Service.

How to Install Java Version 11 on ubuntu 18.04 machine

Before you dive into the installation of Jenkins on your ubuntu machine, you will need Java as a prerequisite, without which Jenkins will not work. So, let’s begin and learn how to Install Java Version 11 on an Ubuntu 18.04 machine using a few basic steps.

  • Firstly, install java using the apt install command as shown below.
sudo apt install default-jdk  # Here we are installing Java Version: Java SE 11 (LTS)
  • Next, verify the java version on your machine.
java -version               # To check the Installed Java Version
Checking the Java version
Checking the Java version
  • Check the location of java by using the which and where command.
which java :         # It will locate executable file location which is /usr/bin/java 
whereis java         # It will give the location  of all the files related to Java 
Checking the Java location
Checking the Java location

The Installation directory of Java is /usr/lib/jvm/java-1.8.0-openjdk-amd64, and this confirms that Java is successfully installed on our ubuntu 18.04 machine. Now, let us install Jenkins.

How to Install Jenkins on Ubuntu 18.04 LTS

Now that you have Java installed on your ubuntu machine. Now, it’s time to install Jenkins, an easier and more straightforward task. Let’s dive in to install Jenkins on Ubuntu 18.04 LTS machine.

  • First, update your system packages on the ubuntu machine using the below command.
sudo apt update
  • Next, add Jenkins Public key to your system so that this key can trust the jenkins.io site to download the repository or any packages.
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
  • Now, add the Jenkins repository to your system and update your system.
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > \
    /etc/apt/sources.list.d/jenkins.list'
sudo apt-get update
  • Now install the Jenkins package using the apt-get command.
sudo apt-get install jenkins

As of now, Jenkins service should be up and running. To check the status of Jenkins, run the below command as shown.

service jenkins status
Checking the Java Service status
Checking the Java Service status

How to setup Jenkins on ubuntu

Now that you have installed Jenkins on your ubuntu machine successfully and verified by running the service command. But the installation is just an initial stage; you will need to set the Jenkins to make it work properly. Let’s learn step by step how to set Jenkins instance.

  • Open the Jenkins instance on your favorite web browser by going to <Jenkins-installation-server-ip-address>:8080.
  • As soon as the URL is opened, it will prompt for the administrator password. The password can be found on /var/lib/Jenkins/secrets/initialAdminPassword directory, as shown below.
Unlocking the Jenkins initial password
Unlocking the Jenkins initial password
  • Now obtain the password by going to the Jenkins server and viewing the following content.
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
  • After successfully adding the Jenkins admin password, you will be prompted for Plugins installation. We will select the Install Suggested Plugins option as this is the demo.
Installing Plugins in Jenkins
Installing Plugins in Jenkins
Plugins installing and Jenkins getting started
Plugins installing and Jenkins getting started.
  • Once the plugins are successfully installed, then it will prompt to create a First admin user. Please fill in the required information and keep it safe with you, as you will use this later to log in.
Creating first Admin User in Jenkins
Creating the first Admin User in Jenkins
  • Now Jenkins URL configuration screen will appear, and you can keep the default URL as it is and click on save and finish.
Configuring the Jenkins Instance
Configuring the Jenkins Instance
Jenkins is ready to be used
Jenkins is ready to be used.
  • Now Jenkins instance is ready for use. Click “Start using Jenkins.” After you click, you will see Jenkins Dashboard, where you create New Jobs by clicking on New Item.
Jenkins Dashboard
Jenkins Dashboard

Workflow of Jenkins deployment

This section is an additional section that provides you a basic overview of how a Jenkins deployment happens step by step and what Jenkins can do for you. Let’s get into it.

  • Once Jenkins is installed, install plugins as per the requirement, whether terraform, bitbucket, python, blue-ocean, etc.
  • Jenkins is configured so that it can fetch the code from any of the repositories such as GIT, bitbucket, SVN, or TFS.
  • Once you define the code repository, Jenkins pulls the code, compiles it using plugins if required, and later builds it. You can include a few test cases along with a build to test some functionalities of code.
  • Later you deploy the code on required environments such as AWS, GCP, Windows machines, Linux machines, etc.
Jenkins deployments workflow
Jenkins deployments workflow

Join 46 other followers

Conclusion

In this tutorial, you learned what Jenkins is, how to install Java on the ubuntu 18.04 machine, how to Install Jenkins on Ubuntu 18.04 LTS, and how to set up Jenkins on ubuntu and setup.

Jenkins is a handy tool for CI and CD purposes and is most widely used, which helps manage your organization’s deployments.

Now that you have Jenkins installed and set up, which application are you planning to deploy?

One thought on “How to Install Jenkins on Ubuntu Machine Step by Step

  1. Pingback: The Ultimate Guide : Getting Started with Jenkins Pipeline

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s