How to install Jenkins on Ubuntu 18.04 LTS server

In this post we will install Jenkins on Ubuntu 18.04 LTS server. For installing the Jenkins, we will use ‘Generic Java Package (war)’. Jenkins is very popular automation server widely use for building,deploying and automating the projects.

It is one of the Open Source Software which is mostly prefer for CI/CD. There are lots of Jenkins plugins available which helps to enhance the function and features.

Hardware and Software Requirements For Jenkins

In this section, we will list Hardware and Software requirements both for installing and managing the Jenkins.

Recommended Hardware Configuration

This is recommended hardware requirements to start with small team. As your requirement grows you have to increase the hardware specs.

  • 1GB RAM or more
  • 50GB or more disk space

Software Prerequisites For Installing Jenkins (war)

  1. Jenkins Stable LTS version 2.138.x [Generic Java Package (war)]
  2. Java version 8
    • Only Java 8 is supported (Both 32 and 64 bit)
    • Older than Java 8 is not supported
    • Java 9 is not supported
    • Java 10 and 11 has preview support

Steps To Install Jenkins On Ubuntu 18.04 LTS Server

In this section, we are installing Jenkins on Ubuntu 18.04 LTS server. It will be standalone Jenkins server. We always recommend to use LTS(Long Term Support) version for any Operating System or software because it provides support for longer period of time.

Install Java

In this section, we are installing Java and then we will set Java environment.

  1. Login to server
  2. Create directory:
    sudo mkdir -p /opt/java
  3. Download Java:
    curl -L -b "oraclelicense=a" -O
  4. Untar Downloaded Java Package:
    sudo tar -xvzf jdk-8u192-linux-x64.tar.gz -C /opt/java/
  5. Rename Directory:
    sudo mv /opt/java/jdk1.8.0_192/ /opt/java/jdk8

Set Java Environment

Now set the Java environment.

  1. Create New Profile Script: We use vi/vim. Use your favorite file editor.
    sudo vi /etc/profile.d/

    And write following contents in script and save the file.

    export JAVA_HOME=/opt/java/jdk8
    export PATH=/opt/java/jdk8/bin:$PATH
  2. Change the script permission:
    sudo chmod +x /etc/profile.d/
  3. Immediate Java Environment Effect: After setting Java Environment, to make it effective either logout and login again.
    Alternatively, you can also run the source command like this.

    sudo source /etc/profile.d/
  4. Check Java version:
    java -version

    Example from our system.

    root@server01:/home/user1# java -version 
    java version "1.8.0_192" 
    Java(TM) SE Runtime Environment (build 1.8.0_192-b12) 
    Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode) 

Create User For Jenkins

We will create user which will be used by Jenkins Application.

  1. Create user called jenkins and change its shell to bash:
    useradd -d /home/jenkins -m jenkins
    sudo usermod -s /bin/bash jenkins

Install Jenkins by using java war file

In this section, we will use Generic Java war file for installing Jenkins. Always use LTS version.

  1. Create directory for keeping Jenkins war file:
    sudo mkdir -p /opt/jenkins
  2. Download Jenkins war file to /opt/jenkins directory:
    wget -P /opt/jenkins/
  3. Change owner,group and permission of jenkins war file
    sudo chown jenkins:jenkins /opt/jenkins/jenkins.war
    sudo chmod +x /opt/jenkins/jenkins.war
  4. Switch to Jenkins user
     sudo su - jenkins
  5. Execute Jenkins war file:
    This is important step, when we first time execute the jenkins war file and all goes well then at the end of output it will show temporary jenkin’s admin password which also saved in the file.

    Execute the Jenkins war file.

    $java -jar /opt/jenkins/jenkins.war
  6. Get Jenkins admin initial temporary password:
    Wait for execution process to reach at the point when you found this line “INFO: Jenkins is fully up and running”

    You will also find the temporary initial admin password for Jenkins, copy the password. Here is the sample output.

    Jenkins initial setup is required. An admin user has been created and a password generated. 
    Please use the following password to proceed to installation: 
    This may also be found at: /home/jenkins/.jenkins/secrets/initialAdminPassword 
  7. Further installation from Web Interface
    In web browser’s address field type Jenkins server ip address or FQDN and use port 8080 to open.
    Jenkins by-default run on port number 8080 (For example

    Note:ip addr list command will show your server ip address.

    Rest of the installation process is very simple and by reading instruction on screen you can easily complete the setup.

  8. Give temporary admin password which you have got from Step 6. ( Do not use our one, the temporary admin password should be generated in your system on doing Step 6)

    Install jenkins

  9. Click on “Install Suggested Plugins”, it will by-default install all plugins suggested by Jenkins. You can also select a few plugins, for this you have to click “Select plugins to install”

    We recommend to go for “Install Suggested Plugins”.

    Install jenkins on Ubuntu

  10. Now it will start installing the plugins as shown in given below screenshot.
    Install jenkins on Ubuntu 18.04 LTS

  11. Give Jenkins Admin user name and set its password as per your wish. We recommend to set password containing Alphanumeric Characters because it is a good security practice.

    Click “Save and Continue” button after setting Jenkin’s admin username and password.

    Install jenkins on Ubuntu 18.04 LTS server

  12. You will see Jenkins URL information on screen. Click “Save and Finish”.
  13. In next screen, you will see “Jenkins is ready!”. Quite obvious click on “Start Using Jenkins”
    installing Jenkins on Ubuntu 18.04 LTS server
  14. Immediate after click, you will be login to Jenkins Admin Console. You will get first screen of Jenkins.
    installing Jenkins on Ubuntu

In next step we will create Jenkins systemd script. Press CTRL+C on terminal where you have executed the Jenkins war file to run the process.

Create systemd script for Jenkins

Logout from jenkins user shell (Press CTRL+D or type command exit)

  1. Create Jenkins system script file
  2. sudo vi /etc/systemd/system/jenkins.service

    Write the below given contents in file jenkins.service

    Description=Jenkins Daemon 
    ExecStart=/opt/java/jdk8/bin/java -jar /opt/jenkins/jenkins.war 
  3. Give Permission
    sudo chmod 755 /etc/systemd/system/jenkins.service
  4. Reload Systemd Daemon:
    sudo systemctl daemon-reload
  5. Manage Jenkins Service: After creating Jenkins systemd script, you can easily manage the Jenkins service.

    # To start jenkins service

    sudo systemctl start jenkins

    # To stop jenkins service

    sudo systemctl stop jenkins

    # To restart jenkins service

    sudo systemctl restart jenkins

    # To check status of jenkins service

    sudo systemctl status jenkins

    # To enable jenkins service to run at booting time

    sudo systemctl enable jenkins

    # To disable jenkins service to run at booting time

    sudo systemctl disable jenkins

I hope now you are able to run your Jenkins server. To update/upgrade Jenkins or its plugins you can do directly from its admin console and for this you receive notification on admin console (by-default).