Installing the Latest VirtualBox on Debian/Ubuntu

The Debian repository already has a VirtualBox package for us to directly install on our systems. But it’s a version older than the latest official release. As of this writing, the version available in the apt sources is 5.2, while the latest one is version 6.1. So let’s see how we can go about installing the latest VirtualBox on Debian.

Installing the Latest Official Release of VirtualBox

There are a few steps to follow for the first time when you try to install the latest version of VirtualBox in your Ubuntu system. Once these steps are complete, all future releases will be available as a direct install package using the apt install command. Let’s begin!

We’ll first add the VirtualBox official source to our apt sources list. You can use your favorite editor for this. I’ll be making use of the nano terminal text editor. So, we need to edit the /etc/apt/sources.list file which is where the apt sources are listed and add the VirtualBox source.

Add VirtualBox source in the apt sources file

root@HowLinux:~# nano /etc/apt/sources.list

We’ll need to add the following line at the end of the file. Replace the <distribution name> part with the name of your distribution. You won’t need to go searching for it as you will find the name right after the URL in the sources file.

deb [arch=amd64] https://download.virtualbox.org/virtualbox/debian <distribution name> contrib

As you can see in the screenshot below, the distribution name in my case is bionic and is written in all the lines in the sources file.

VirtualBox Sources
VirtualBox Sources

Verify if GnuPG and Wget are installed

Before we can import the public keys, we need to ensure we have the GnuPG and the WGet package installed. To check if this package GnuPG package is already installed, type the command gpg in your terminal. You should see a prompt similar to the one below.

Gpg Installed
Check if GnuPG is installed

For verifying if the wget command is installed, we’ll type wget in the terminal. If it shows you a prompt like the one below, you have wget installed too.

Wget Install Verify
Verify if wget is installed

If either of the commands is not installed, you can run apt install gnupg or apt install wget to download the packages.

Import VirtualBox Public Keys

Now let’s import the public keys for VirtualBox. For Debian versions above 8, and Ubuntu versions above 16, you can use the below link:

https://www.virtualbox.org/download/oracle_vbox_2016.asc

For older distributions, we’ll use:

https://www.virtualbox.org/download/oracle_vbox.asc

We’ll download these files and add them to our systems using the wget and the apt-key add commands. Let’s do that now.

root@HowLinux:~# wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc
Download Keys Using Wget
Download Keys Using Wget

We’ll install the keys using the apt-key add command now.

root@HowLinux:~# apt-key add oracle_vbox_2016.asc
OK
Apt Key Add Command Virtualbox
Apt Key Add Command Virtualbox

Install the Latest VirtualBox Package

Now, finally comes the fun part. Installing and running the VirtualBox package. We’ll first update our sources and then install VirtualBox.

root@HowLinux:~# apt update 
root@HowLinux:~# apt install virtualbox-6.1
Apt Install Virtualbox
Apt Install Virtualbox

This will install a lot of packages automatically for you. Sit back and watch it all get installed. Once done, you’ll have the latest VirtualBox installed on your Debian system ready to be used!

Conclusion

Finally, we have the latest version of Virtualbox installed in our system. Apart from having the latest version installed, we also have the sources list updated so any future releases of VirtualBox can directly be downloaded using the apt install virtualbox-x.x command where x.x is the latest version.