March 6, 2018 · EN snippets

Install Oracle VirtualBox on Ubuntu & Debian

Default ubuntu repos do not seem to contain the latest version of Oracle VirtualBox. However, it can easily be installed on Ubuntu (17.10 & 16.04 and 14.04) and Debian (9 & 8) with the following instructions. Copy and paste the following python lines into a python file named and execute it with sudo privilleges.

The code will determine your OS version, fetch the appropriate packages and install it.

import subprocess
import os

version = subprocess.check_output(['lsb_release', '-a'])

ub1710 = 'deb zesty contrib'
ub1604 = 'deb xenial contrib'
ub1404 = 'deb trusty contrib'
deb9   = 'deb stretch contrib'
deb8   = 'deb jessie contrib'

# step 1 : edit /etc/apt/sources.list

sources_list = '/etc/apt/sources.list'
sources_file = open(sources_list, 'a')

if 'ubuntu' in version.lower():
    if '17.10' in version:
    elif '16.04' in version:
    elif '14.04' in version:
elif 'debian' in version.lower():
    if '9' in version:
    elif '8' in version:


# step 2 : add sign keys

os.system('wget -q -O- | sudo apt-key add -')
os.system('wget -q -O- | sudo apt-key add -')

# step 3 : install virtualbox

os.system('apt-get update')
os.system('apt-get install virtualbox-5.2')

print ('\nVirtualbox has been installed!\n')

Run the script

sudo python

That should install the latest version (as of now 5.2.8) of VirtualBox.

The complete script can be downloaded here.*

* md5sum : 4880da544333f72aa1652f5547a24d67