VirtualBox is a free, open-source virtualization application developed by Oracle that lets you run a complete operating system inside a window on your existing Debian 12 system. Each virtual machine runs independently, using a dedicated slice of your CPU, RAM, and disk space, while leaving the host system untouched. This makes it ideal for testing distributions, running isolated development environments, or trying software you would not want installed directly on your main system.
This guide walks through installing VirtualBox on Debian 12 from the official Oracle repository, adding the Extension Pack for USB and remote desktop support, and creating your first virtual machine. Before running any commands, make sure your user account has sudo privileges on Debian 12.
Quick Answer
Run these four commands in sequence to install VirtualBox 7.0 on Debian 12:
sudo apt install curl wget gnupg2 lsb-release -y
curl -fsSL https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/vbox.gpg
echo "deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list
sudo apt update && sudo apt install virtualbox-7.0 -y
Launch VirtualBox from the Activities menu after installation completes.
How to Install VirtualBox on Debian 12
Step 1: Install the curl Utility
The curl command downloads data from a server using the terminal. Install it alongside wget and gnupg2, which are needed to fetch and verify the VirtualBox repository signature:
sudo apt install curl wget gnupg2 lsb-release -y

Step 2: Download the VirtualBox GPG Key
Download the official VirtualBox GPG key and save it to the trusted keys directory. This lets apt verify that packages from the VirtualBox repository are genuine:
curl -fsSL https://www.virtualbox.org/download/oracle_vbox_2016.asc|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/vbox.gpg

Step 3: Add the VirtualBox Repository and Update
Add the official VirtualBox repository to /etc/apt/sources.list.d so apt can find and download VirtualBox packages:
echo "deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list

Update the package lists to include the new repository:
sudo apt update

Step 4: Install the Required Kernel Headers
VirtualBox requires kernel headers and DKMS to build its kernel modules. DKMS automatically rebuilds those modules whenever your kernel is updated, so VirtualBox keeps working after system upgrades:
sudo apt install linux-headers-$(uname -r) dkms -y

Step 5: Install VirtualBox
Install VirtualBox 7.0 from the Oracle repository you added:
sudo apt install virtualbox-7.0 -y

Verify the installation by checking the installed version:
vboxmanage -v | cut -dr -f1

Step 6: Add Your User to the vboxusers Group (Optional)
To pass USB devices through to guest virtual machines, add your user account to the vboxusers group. Replace user with your actual username:
sudo usermod -aG vboxusers user

Activate the new group membership in the current shell without logging out:
newgrp vboxusers

Step 7: Install the VirtualBox Extension Pack (Optional)
The VirtualBox Extension Pack adds USB 2.0/3.0 support, webcam pass-through, VirtualBox Remote Desktop Protocol (VRDP), and disk image encryption. Download it with wget:
wget https://download.virtualbox.org/virtualbox/7.0.14/Oracle_VM_VirtualBox_Extension_Pack-7.0.14.vbox-extpack

Install the downloaded Extension Pack:
sudo vboxmanage extpack install Oracle_VM_VirtualBox_Extension_Pack-7.0.14.vbox-extpack

When prompted to accept the license terms, enter y to continue:

Confirm the Extension Pack is installed correctly:
vboxmanage list extpacks

How to Use VirtualBox on Debian 12
With VirtualBox installed, here is how to create and start your first virtual machine:
Step 1: Create a New Virtual Machine
Launch VirtualBox from the Activities menu. Click Machine then New, or press Ctrl + N, to open the new VM wizard:

Step 2: Specify Virtual Machine Details
Enter a Name for your VM, choose the Folder where VirtualBox will store its data, and select the ISO Image of the operating system you want to install. Uncheck Skip Unattended Installation to let VirtualBox handle the OS setup automatically using the credentials you provide in the next step:

Step 3: Add User Details
On the Unattended Guest OS Install Setup screen, enter the Username and Password for the guest OS. You can also set a custom Hostname and Domain Name for the virtual machine:

Step 4: Allocate System Resources
Set how much RAM and how many CPU cores the virtual machine can use. A minimum of 2 GB RAM and 2 CPU cores works for most lightweight guest operating systems:

On the next screen, set the virtual hard disk size. Most guest operating systems need at least 20 GB of disk space:

Review the summary and click Finish to create the virtual machine:

Step 5: Start the Virtual Machine
Select the VM from the left pane of Oracle VM VirtualBox Manager and click Start. VirtualBox launches the guest OS installation automatically using the ISO image you selected. Follow the on-screen prompts to complete the installation:

How to Remove VirtualBox from Debian 12
To uninstall VirtualBox completely, run:
sudo apt remove --purge virtualbox
To also delete all virtual machines and their configuration files, run these two commands:
sudo rm ~/"VirtualBox VMs" -Rf
sudo rm ~/.config/VirtualBox/ -Rf