How to install Jenkins on Ubuntu 18.04 in VirtualBox
Tags: jenkins, ubuntu, devops, virtualbox
Published: 2020-04-05 20:58:55


This article was first published on [razcodes.dev](https://razcodes.dev "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](https://www.virtualbox.org/ "VirtualBox").

## Preparing Ubuntu Install
Once you have that up and running, go and download the ISO for [Ubuntu Server](https://ubuntu.com/download/server "Ubuntu"). 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.

```bash
sudo apt update && sudo apt upgrade
```

## Installing Jenkins

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

```bash
sudo apt install -y openjdk-8-jre
```

Next we will add the Jenkins key to our system.

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

Add source packages

```bash
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

```bash
sudo apt update && sudo apt install jenkins
```

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

```bash
sudo systemctl enable jenkins
```

## Final setup

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

```bash
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:

```bash
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.