Setting up Jenkins on Ubuntu dedicated server

As a developer, often you are blocked by repetitive tasks that need be done. This is something that can become frustrating, but luckly we have some tools to help. In the following lines we will talk about Jenkins, an automation server written in Java.


  • Your Ubuntu has a public IP address
  • Your sudo username is: admin
  • Your host is:
  • You have a cname DNS entry for every subdomain of pointing to itself.

The setup

Please note that there are commands which are not mandatory and everything can be adapted to the needs of your system (e.g. You might choose not to use nginx)

Sudo user

  • sudo apt-get update
  • adduser admin
  • usermod -aG sudo admin
  • sudo passwd -l root
  • su - admin

The locale

  • locale
  • sudo apt-get install language-pack-en-base
  • sudo dpkg-reconfigure locales


If using digitalocean, swap is not recommended.

  • sudo swapon --show
  • sudo fallocate -l 4G /swapfile
  • ls -lh /swapfile
  • sudo chmod 600 /swapfile
  • ls -lh /swapfile
  • sudo mkswap /swapfile
  • sudo swapon /swapfile
  • sudo swapon --show

Make swap permanent

  • sudo nano /etc/fstab
    and add at the end:
    /swapfile none swap sw 0 0


  • sudo ufw allow 8080
  • sudo ufw allow OpenSSH
  • sudo ufw enable

Setup java

  • sudo apt-get install default-jre


  • sudo apt-get install jenkins
  • sudo systemctl start jenkins
  • sudo systemctl status jenkins
  • sudo nano /var/lib/jenkins/secrets/initialAdminPassword
  • Access `` to finish setup.

“Package ‘jenkins’ has no installation candidate”

  • wget -q -O - | sudo apt-key add -
  • sudo sh -c 'echo deb binary/ > /etc/apt/sources.list.d/jenkins.list'
  • sudo apt-get update

“ubuntu 18.04 jenkins found an incorrect java version”

  • sudo add-apt-repository ppa:webupd8team/java
  • sudo apt install oracle-java8-installer
  • wget -q -O - | sudo apt-key add -
  • sudo apt-add-repository "deb binary/"
  • sudo apt install jenkins


  • sudo apt-get update
  • sudo apt-get install nginx
  • sudo ufw allow 'Nginx HTTP'
  • sudo add-apt-repository ppa:certbot/certbot
  • sudo apt-get update
  • sudo apt-get install python-certbot-nginx
  • sudo nano /etc/nginx/sites-available/default
    • replace `server_name _` with server_name;
  • sudo nginx -t
  • sudo systemctl reload nginx
  • sudo ufw allow 'Nginx Full'
  • sudo ufw delete allow 'Nginx HTTP'
  • sudo certbot --nginx -d -d
  • Choose redirect all traffic to https://

Use Jenkins with ssl nginx

  • sudo nano /etc/nginx/sites-available/default
    • find try_files $uri $uri/ =404;
    • replace with:
      # try_files $uri $uri/ =404;
      include /etc/nginx/proxy_params;
      proxy_pass          http://localhost:8080;
      proxy_read_timeout  90s;
      # Fix potential "It appears that your reverse proxy set up is broken" error.
      proxy_redirect      http://localhost:8080;
  • sudo nano /etc/default/jenkins
    • find
      JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT"
    • replace with:
      JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT --httpListenAddress="
  • sudo systemctl restart jenkins
  • sudo systemctl restart nginx
  • Go to: and choose: Manage jenkins > Configure system and update Jenkins location > Jenkins URL to


For a better UI/UX experience, you could install the BlueOcean plugin, from the jenkins available plugins.


  • curl -fsSL | sudo apt-key add -
  • sudo add-apt-repository "deb [arch=amd64] $(lsb_release -cs) stable"
  • sudo apt-get update
  • apt-cache policy docker-ce
  • sudo apt-get install -y docker-ce