Overview
In this tutorial, you will learn how to install VirtualBox 7 on Ubuntu 20.04. Virtualbox is a very popular open source hypervisor, primarily due to it being free and very powerful.
So popular is Virtualbox that a lot of DevOps workflows are based on it, as well as local Kubernetes environments. Vagrant, a tool used to create and run preconfigured operating systems is heavily used with VirtualBox, as is Minikube, the most popular local Kubernetes environment for developers.
The best method for installing VirtualBox on Ubuntu is directly from the official Debian repository. This provides you with access to every VirtualBox release, as well as their extension packs.
Install from Ubuntu Repository
VirtualBox 6.1 is available directly from the Ubuntu 20.04 package repository. To install it, run the following command.
sudo apt install virtualbox
While this is convenient, Ubuntu and Debian pride themselves on building stable operating systems. A great goal for promoting an operating system for production use, it also means the packages available on receive bug and security patches.
Major and minor releases do not make their way to Ubuntu’s or Debian’s package repositories. If you want want to run more recent versions of VirtualBox you will need to add the official VirtualBox repository to your repository list.
Add VirtualBox Repository
Before you can use the official VirtualBox repository you should install the keys for it. This ensures your downloaded package hasn’t been tampered with.
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
With the keys installed it’s time time add the VirtualBox repository.
echo "deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian $(lsb_release -sc) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list
If successfully added, you should get the following output.
Update your repository cache to add the contents of the virtualbox repository.
sudo apt update
You can verify the virtualbox repostories were added and have pulled down data to your local cache, if you see the following entries in your apt update
output.
Get:6 http://download.virtualbox.org/virtualbox/debian focal InRelease [4,428 B]
Get:7 http://download.virtualbox.org/virtualbox/debian focal/contrib amd64 Packages [1,475 B]
Fetched 5,903 B in 1s (5,209 B/s)
Reading package lists... Done
Installing VirtualBox
Before you install Virtualbox you should install updated Linux kernel headers. This ensure VirtualBox is compiled correctly for your host.
sudo apt install linux-headers-$(uname -r) dkms
And finally, install VirtualBox with the apt install
command.
sudo apt install virtualbox-6.1
Install VirtualBox Extension Pack
The extension pack provides a lot of usefully functionality to Virtualbox. One example is the ability to mount USB drives onto your virtual machine. To install the extension pack, run the following command.
sudo apt install virtualbox-ext-pack
Alternatively, the extension pack can be downloaded from Oracle over HTTP.
wget https://download.virtualbox.org/virtualbox/6.1.6/Oracle_VM_VirtualBox_Extension_Pack-6.1.6.vbox-extpack
Conclusion
In this tutorial you learned how to install VirtualBox 6 on Ubuntu 20.04. You learned how to use the default Ubuntu 20.04 repository to install it, as well as adding the official Virtualbox repository for more recent releases.