Install Jenkins on Ubuntu in 10 Easy Steps

Install Jenkins on Ubuntu

Jenkins 2.x has lots of great functionalities that will make the CI pipeline smooth using the pipeline as code and reusable with shared libraries.

In this guide, we will walk you through the steps to install Jenkins on a Ubuntu server and use all recommended configurations in 10 easy steps.

Also, we have added the steps to install Jenkins using Docker on the Ubuntu server.

Follow the steps given below to install and configure Jenkins 2 on a ubuntu server.

Note: Centos/Rehat users follow this tutorial Install jenkins on centos/Redhat

Step 1: Log in to the server and update the package list.

sudo apt-get -y update

Step 2: Jenkins needs the Java runtime as it is based on Java. Install open JDK 11 package using the following command.

sudo apt install openjdk-11-jdk -y

Step 3: Add the Jenkins Debian repo.

wget -q -O - https://pkg.jenkins.io/debian/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > \
    /etc/apt/sources.list.d/jenkins.list'

Step 4: Update the package list again.

sudo apt-get update -y

Step 5: Install latest LTS Jenkins.

Note: You can check the official Jenkins ubuntu package repo for more information on the latest versions

sudo apt-get install jenkins -y

Step 6: Start the Jenkins service & enable it for starting during bootup.

sudo systemctl start jenkins
sudo systemctl enable jenkins

You can check the status of Jenkins service using the following command.

sudo systemctl status jenkins

Step 7: Now you will be able to access the Jenkins server on port 8080 using the IP address as shown below.

Note: You can also run Jenkins on port 80. Check this Jenkins guide to change access port

Step 8: As you can see in the above image, you need to provide the administrative password. You can get the password using the following command.

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

Copy the password and click continue.

Step 9: Next, you will be asked to configure plugins as shown below. Select the “Install Suggested Plugins” option. This will install all the required plugins for building your projects. It will take a few minutes to install the plugins.

Step 10: Once installed, You need to create a user with password and click “save and finish”

Click “Start Using Jenkins” and it will take you to the Jenkins Dashboard. Log in using the username and password that you have given in step 8.

That’s it! Now you have a fully functional Jenkins server up and running. Consider setting up Jenkins backup using the backup plugin.

Jenkins Agent Setup

Next, you need to configure a distributed master-slave setup wherein you will have an active master and slave agents for building the projects.

Follow the Jenkins master-agent setup guide to configure a Jenkins agent

If you are looking for a cloud Docker agent, follow the Docker-based Jenkins build agents guide.

SSL for Jenkins URL

If you are setting up a Jenkins server for a project, consider setting up SSL for the Jenkins server URL.

Follow the Jenkins SSL setup guide to configure SSL.

Jenkins Key Configurations on Ubuntu

Here are some key configurations and file locations in Jenkins that you should know.

Note: The recommended approach is to mount the Jenkins data folder to an additional data disk for production setup. This way, you don’t lose any Jenkins data if the server crashes.

Jenkins Data Location/var/lib/jenkins
Jenkins main configuration file/var/lib/jenkins/config.xml
Jenkins Jobs folder/var/lib/jenkins/jobs

Setting up Jenkins Using Docker on Ubuntu

If you are a docker user, you can run Jenkins on a docker container.

Refer docker installation document to install the latest edition of docker.

Execute the following command to deploy Jenkins on Docker

docker run -p 8080:8080 -p 50000:50000 --name jenkins jenkinsci/jenkins:latest

The above command won’t persist any changes if the container crashes. So it is better to mount a host volume to the container to hold all the Jenkins configurations.

Here is the command to deploy Jenkins container with the host volume mount.

docker run -p 8080:8080 -p 50000:50000 -v /home/ubuntu:/var/jenkins_home jenkinsci/jenkins:latest

Setting up Ubuntu Based Jenkins on Kubernetes

You can run Jenkins on Kubernetes using the ubuntu based docker image for Jenkins.

Follow our Jenkins deployment on kubernetes guide.

Consider using a kubernetes persistent volume to mount the data directly to avoid data loss if the Jenkins pod restarts.

Conclusion

In this guide, you have learned to install Jenkins on ubuntu server using different methods.

After the installation, make sure you backup the Jenkins data folder before making any major changes to the configurations. For some reason, if you break Jenkins, you can easily restore it from the backup files.

11 Shares:
11 comments
  1. This is not directly regarding this article.but I found it difficult to install maven in Jenkins 2.7.2 . Previously I used auto installer. but I haven’t found that option in this version.

      1. Thank you for your response. Jenkins Moved this option to global tool configuration, I guess they wanted Jenkins to be more organized, which put me in trouble. 😀

  2. Hello! I have problem with step 5. if I understand clearly I have to open file etc/rc.local and then print the line above exit 0 : /etc/init.d/jenkins start. but it says that etc/rc.local is for read only.

  3. Hi,

    I tried to set up this way and I’m able to get to the “Getting Started” page, but when I’m giving the password it’s not moving forward. It’s not throwing any error.

    Any idea, why this is happening?

    Regards
    Sammi

      1. Looks like the problem is with the latest versions 2.7 and 2.8. I installed 2.0 and this problem was not there.

        Regards
        Sammi

        1. Hi Sammi, we tried with 2.9 and everything is working fine. Also we have updated the article. Thank you for posting the issue!

      2. Run this command to know the password.
        $docker exec jenkins-master cat /var/jenkins_home/secrets/initialAdminPassword

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like