---
Classes:
  - IT Foundations
---

# VirtualBox

# Alternative

If the situation doesn't specifically require VirtualBox and you can use any Hypervisior, I strongly suggest using [Virtual Machine Manager](VirtualMachineManager.md) (virt-manager); as it uses KVM, which has support built into the kernel, which means a much simpler install for some distributions and less potential for issues.

# Install

Note: After install a reboot may be required.
Most distributions package it in their repositories and can be installed as such:

## Arch-based

```sh
sudo pacman -S virtualbox
```

## Debian
Debian doesn't package virtualbox in the offical repositories, so we need to add VirtualBox's repository. Source: https://www.virtualbox.org/wiki/Linux_Downloads

Replace `<mydist>` in the first command with `trixie` or the current version of Debian if you are on a newer **stable** version.
```sh
# Add virtualbox repository to system
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/oracle-virtualbox-2016.gpg] https://download.virtualbox.org/virtualbox/debian <mydist> contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list
# Add VirtualBox's signing keys to system
wget -O- https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo gpg --yes --output /usr/share/keyrings/oracle-virtualbox-2016.gpg --dearmor
# Update package list and install virtualbox
sudo apt update
sudo apt install virtualbox-7.2 
```
Note: For the last command you can type up to `sudo apt install virtualbox-` and triple tap TAB to see what version options there are.

## Fedora
Fedora doesn't package virtualbox in the offical repositories, so we need to add the RPMFusion repository which packages additional software, including virtualbox.
RPMFusion is a long-standing repo operated by some of the same contributors as the main Fedora repos; it just contains things that Redhat cannot legally distribute.

### Install VirtualBox
```sh
# Import the RPMFusion repository
sudo dnf install https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-$(rpm -E %fedora).noarch.rpm
# Install virtualbox
sudo dnf install virtualbox
```
When prompted to import the RPMFusion key, ensure it has the below signature, then input "y"
```
E9A4 91A3 DE24 7814 E7E0 67EA E06F 8ECD D651 FF2E
RPM Fusion free repository for Fedora (2020) <rpmfusion-buildsys@lists.rpmfusion.org>
```
If you don't use secure boot, you can simply reboot and skip to the Check functionality stage

### Sign VirtualBox modules
Now, assuming you are using secure boot, we will need to allow the kernel modules used by virtualbox. We will do this using akmods
```sh
# enable akmods if it not already
sudo systemctl enable --now akmods
# Register the key with Secure Boot (MOK)
sudo mokutil --import /etc/pki/akmods/certs/public_key.der
```
That last command will prompt you for a password, it can be whatever, just be sure to remember it.

1. Reboot
2. Once you get a blue menu press any key to enter MOK management. 
   - If you miss this prompt you can re-run the last command and reboot again.
3. Select `Enroll MOK` and follow the prompts to enroll the key
4. Enter the password you chose when prompted

### Check functionality 
Once booted you can now ensure the VirtualBox module is working with
```sh
systemctl status vboxdrv
```
And ensure it it started.

## Ubuntu/Mint

```sh
sudo apt install virtualbox
```

