DEV Community

Raz
Raz

Posted on

How to install Jenkins on Ubuntu 18.04 in VirtualBox

This article was first published on razcodes.dev

The following will show you how to install Jenkins on Ubuntu Server 18.04 that you will get up and running in VirtualBox on your machine. I wrote this using a mac, but it should be the same on other operating systems.

VirtualBox is a virtualization tool that allows you to create multiple virtual machines and have them run on your computer. You can download it and install it directly from their website.

Preparing Ubuntu Install

Once you have that up and running, go and download the ISO for Ubuntu Server. For this demo I used version 18.04 LTS.

  • In VirtualBox, click on New
  • Fill in the name (ex: Ubuntu - Jenkins), type (Linux), and version (Ubuntu 64-bit), then click Continue
  • For memory, I went with 2048 MB
  • Create a virtual hard disk now
  • Chose VDI
  • Dynamically allocated
  • I gave it 16GB of space

With the new machine created and selected, right click and chose Settings, then click on Storage. Select the Empty option under the IDE controller and then on the right side of the interface click on the disk icon, which will allow you to point it to the ISO you downloaded.

Go to the Network tab, and select Bridged Adapter. I like to use this option because it gives the new machine an IP address on the network, instead of just a local one. Click OK.

Now you can start the new Virtual machine.

Installing Ubuntu

Once the installation starts, you can move around using the tab key or arrow keys. I mostly left everything as default, unless noted otherwise.

  • select your language
  • keyboard layout and variant
  • network
  • proxy
  • mirror
  • Use An Entire Disk
  • select the disk
  • Done
  • Continue
  • Fill in your name, desired server name, username and password
  • press space to Install OpenSSH server (optional)
  • Done

When the installation is complete, select Reboot, then press Enter when asked to remove the install media.

You can login, using the credentials you setup earlier. First, you should apply all the available patches to your new system.

sudo apt update && sudo apt upgrade

Installing Jenkins

In order for Jenkins to work we will need to install Java.

sudo apt install -y openjdk-8-jre

Next we will add the Jenkins key to our system.

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

Add source packages

sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'

Now we can run another update and install Jenkins

sudo apt update && sudo apt install jenkins

And now, just to make sure that Jenkins will restart when the system is rebooted:

sudo systemctl enable jenkins

Final setup

You can now get the IP of your new system using the following command:

ifconfig | grep inet

You can take your ip address and add :8080 at the end of it and paste it in the browser. That will bring up the Jenkins setup (ex: 192.168.1.49:8080)

To pass this first screen you will need the secret key that was created during the install, so back on the server you can get that key like so:

sudo cat /var/lib/jenkins/secrets/initialAdminPassword
  • take the output of that key and put it in the browser
  • chose if you want to install the default plugins or none
  • fill in your desired username, password and email for Jenkins
  • take note of your new URL
  • start using Jenkins

That’s all folks. You should have a brand new VM Ubuntu Server running Jenkins.

Top comments (0)