Virtualbox: Installation in Debian 9

Steps

Add source list

Add the following line to your /etc/apt/sources.list. According to your distribution, replace '<mydist>' with 'artful', 'zesty', 'yakkety', 'xenial', 'trusty', 'stretch', 'jessie', or 'wheezy' (older versions of VirtualBox supported different distributions):

deb https://download.virtualbox.org/virtualbox/debian stretch contrib

Add sources signatures

wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -

and

wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -

Check signatures (optional)

The key fingerprint for oracle_vbox_2016.asc is

B9F8 D658 297A F3EF C18D 5CDF A2F6 83C5 2980 AECF Oracle Corporation (VirtualBox archive signing key) <info@virtualbox.org>

The key fingerprint for oracle_vbox.asc is

7B0F AB3A 13B9 0743 5925 D9C9 5442 2A4B 98AB 5139 Oracle Corporation (VirtualBox archive signing key) <info@virtualbox.org>

Install

To install VirtualBox, do

sudo apt-get update
sudo apt-get install virtualbox-5.2

Troubleshooting

What to do when experiencing The following signatures were invalid: BADSIG …​ when refreshing the packages from the repository?

sudo -s -H
apt-get clean
rm /var/lib/apt/lists/*
rm /var/lib/apt/lists/partial/*
apt-get clean
apt-get update