VirtualBox is an open-source virtualization platform that runs multiple operating systems simultaneously on a single host machine. Whether you are testing different Linux distributions, running Windows applications on Linux through virtualization, developing cross-platform software, or creating isolated environments for security testing, VirtualBox provides the flexibility to manage diverse virtual machines without dual-booting or maintaining separate physical hardware.
This guide covers importing Oracle’s official repository, installing VirtualBox with matching kernel headers, configuring the Extension Pack for USB 3.0 and RDP support, and setting user group permissions for hardware access. You’ll learn the complete setup from repository configuration through a production-ready virtualization environment with automatic security updates.
Import VirtualBox APT Repository
Update System and Install Repository Tools
First, update your system before installing VirtualBox to ensure kernel headers and dependencies match your current kernel version. This prevents module compilation failures when VirtualBox builds its kernel drivers.
Start by updating the package list to refresh repository metadata:
sudo apt update
Then upgrade installed packages to their latest versions:
sudo apt upgrade
Install Repository Management Tools
Next, ensure repository management tools are available (most Ubuntu installations include these, but this guarantees compatibility):
sudo apt install curl ca-certificates -y
Import VirtualBox GPG Key
Afterward, import Oracle’s GPG key to verify package authenticity. APT uses this key to confirm VirtualBox packages come from Oracle’s official repository and haven’t been tampered with during download:
curl -fSsL https://www.virtualbox.org/download/oracle_vbox_2016.asc | gpg --dearmor | sudo tee /usr/share/keyrings/virtualbox.gpg > /dev/null
Add VirtualBox Repository
Now add the official VirtualBox repository to your system. The $(lsb_release -cs) variable automatically detects your Ubuntu codename (noble, jammy, focal, etc.) so the command works across all supported releases:
cat <<EOF | sudo tee /etc/apt/sources.list.d/virtualbox.sources
Types: deb
URIs: http://download.virtualbox.org/virtualbox/debian
Suites: $(lsb_release -cs)
Components: contrib
Architectures: $(dpkg --print-architecture)
Signed-By: /usr/share/keyrings/virtualbox.gpg
EOF
This configuration uses the modern DEB822 repository format with GPG key verification. Ubuntu fully supports this format and it prevents duplicate repository entries.
Refresh the package index to include VirtualBox packages from the newly added repository:
sudo apt update
Install VirtualBox via APT Command
Install VirtualBox and Kernel Headers
Now install VirtualBox 7.2 with the build tools and kernel headers required to compile its kernel modules (vboxdrv, vboxnetflt, vboxnetadp). The linux-headers-$(uname -r) package matches your running kernel, while build-essential and dkms handle module compilation:
sudo apt install virtualbox-7.2 build-essential dkms linux-headers-$(uname -r) -y
Oracle’s repository also provides
virtualbox-7.1andvirtualbox-7.0if you need an older version for compatibility reasons. Replace the package name in the command above to install a different version.
Verify Installation Source
After installation, confirm VirtualBox installed from Oracle’s repository rather than Ubuntu’s default repositories (which may contain older versions). The output shows the installed version, candidate version, and repository source:
apt-cache policy virtualbox-7.2

This output shows the installed version and confirms the package source is download.virtualbox.org, not Ubuntu’s default repositories.
Check VirtualBox Service Status
Next, verify the vboxdrv systemd service loaded successfully. This service manages VirtualBox kernel modules (vboxdrv, vboxnetflt, vboxnetadp, vboxpci) that handle virtualization, networking, and USB passthrough:
systemctl status vboxdrv

In most cases, the service should show active (exited) status, confirming kernel modules loaded successfully during installation.
If Secure Boot is enabled and the service reports signature or verification errors, enroll the DKMS key so the modules load. Run
sudo mokutil --import /var/lib/shim-signed/mok/MOK.der, set a one-time password, reboot, choose Enroll MOK at the blue screen, and enter the password. After enrollment, rerunsystemctl status vboxdrvto confirm the modules load.
Enable VirtualBox Service (If Required)
If that vboxdrv service shows inactive status, enable it to load kernel modules automatically at boot:
sudo systemctl enable vboxdrv --now
Add User to vboxusers Group
Before launching VirtualBox and creating virtual machines, add your user account to the vboxusers group. This grants access to USB devices, network interfaces, and other hardware features required for full virtualization functionality. Without this group membership, VirtualBox cannot pass through USB devices or configure bridged networking:
sudo usermod -a -G vboxusers $USER
Log out and log back in (or reboot) for group membership changes to take effect. Verify your user now belongs to the vboxusers group:
groups $USER
The output should include vboxusers in the group list. If it doesn’t appear, reboot your system to complete the group membership update.
Launch VirtualBox
Launch VirtualBox from the terminal with a single command:
virtualbox
Alternatively, open VirtualBox from your desktop environment by clicking Activities at the top of your screen, selecting Show Applications, and choosing Oracle VM VirtualBox from the list.

Install VirtualBox Extension Pack (Optional)
The VirtualBox Extension Pack enhances virtual machine functionality with practical features: USB 3.0 support for external drives and devices, RDP (Remote Desktop Protocol) for headless VM access, disk encryption for sensitive data, NVMe storage support, and PXE boot for Intel network cards. Install this pack only if you need external hardware passthrough or remote VM access. The pack requires separate licensing (proprietary components), but Oracle provides it free for personal and evaluation use.
Download VirtualBox Extension Pack
To proceed, download the Extension Pack matching your installed VirtualBox version. First, check your VirtualBox version:
vboxmanage -v | cut -dr -f1
This command returns your version number (for example, 7.0.20). Use it in a variable to download the matching Extension Pack without manual edits:
VBOX_VERSION=$(vboxmanage -v | cut -dr -f1)
wget https://download.virtualbox.org/virtualbox/${VBOX_VERSION}/Oracle_VM_VirtualBox_Extension_Pack-${VBOX_VERSION}.vbox-extpack
Install VirtualBox Extension Pack
Once downloaded, install or upgrade the Extension Pack:
sudo vboxmanage extpack install --replace Oracle_VM_VirtualBox_Extension_Pack-${VBOX_VERSION}.vbox-extpack
During installation, you’ll be prompted to accept Oracle’s Personal Use and Evaluation License (PUEL). Type y and press Enter to accept.
Verify Extension Pack Installation
Confirm the Extension Pack installed successfully and matches your VirtualBox version:
vboxmanage list extpacks
Install Guest Additions Inside Virtual Machines (Optional)
Guest Additions is additional software you install inside each virtual machine (not on the host) to enhance VM performance. It provides shared clipboard, drag-and-drop file transfers between host and guest, shared folders for seamless file access, automatic screen resolution adjustment, and improved video rendering. Install Guest Additions after creating and launching your first virtual machine. The installation process differs slightly between Linux and Windows guests.
Install Guest Additions on Linux Virtual Machines
Inside your Linux guest VM, first install the required build tools and kernel headers needed to compile Guest Additions modules:
sudo apt install build-essential dkms linux-headers-$(uname -r)
Next, mount the Guest Additions ISO from the VirtualBox menu. Click Devices at the top of the VM window, then select Insert Guest Additions CD image. VirtualBox automatically mounts the ISO to your VM:
cd /media/$USER/VBox_GAs_* && sudo sh ./VBoxLinuxAdditions.run
The installer compiles kernel modules and displays progress. After completion, reboot the guest to activate Guest Additions features:
sudo reboot
Install Guest Additions on Windows Virtual Machines
Inside your Windows guest VM, click Devices from the VirtualBox menu bar, then select Insert Guest Additions CD image. Windows automatically detects and mounts the ISO. The VirtualBox Guest Additions installer should launch automatically; if not, open File Explorer, navigate to the CD drive, and double-click VBoxWindowsAdditions.exe to start the installer.
Follow the on-screen prompts to complete the installation. When prompted, accept the default installation settings. The installer may request administrative privileges and ask you to reboot the guest system after completion. Reboot Windows to fully activate Guest Additions features.
Verify Guest Additions Installation
After rebooting your guest (Linux or Windows), verify Guest Additions installed successfully. On Linux, check the kernel module status:
lsmod | grep vboxguest
The output should show vboxguest as a loaded kernel module, confirming successful installation. On Windows, open VirtualBox Guest Additions from the Control Panel or System Tray to verify the installed version.
Test Guest Additions Features
With Guest Additions installed, test the enhanced features. For example, try dragging a file from your host desktop into the guest VM window—the file should transfer directly without requiring external transfer tools. Test shared clipboard by copying text on the host and pasting it into the guest, or vice versa. If you configured shared folders, open File Manager on Linux or File Explorer on Windows and navigate to the shared folder to confirm seamless host-guest file access.
Troubleshooting VirtualBox Installation
Unable to Locate Package dkms or build-essential
If you see E: Unable to locate package dkms or similar errors for build-essential during installation, your system is missing access to Ubuntu’s main and universe repositories. This can happen on fresh installations where the APT sources configuration file is missing or incomplete.
First, check if the Ubuntu sources file exists:
ls -la /etc/apt/sources.list.d/ubuntu.sources
If the file is missing but a backup exists (created during installation), restore it:
sudo cp /etc/apt/sources.list.d/ubuntu.sources.curtin.orig /etc/apt/sources.list.d/ubuntu.sources
If no backup exists, create a minimal sources file that enables the main repositories:
cat <<EOF | sudo tee /etc/apt/sources.list.d/ubuntu.sources
Types: deb
URIs: http://archive.ubuntu.com/ubuntu
Suites: noble noble-updates noble-security
Components: main restricted universe multiverse
Signed-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg
EOF
After restoring or creating the sources file, update the package index and retry the installation:
sudo apt update
sudo apt install virtualbox-7.2 build-essential dkms linux-headers-$(uname -r) -y
vboxdrv Kernel Module Fails to Load
If the vboxdrv service fails to start after installation, the kernel modules may not have compiled correctly. First, check if the required headers are installed for your running kernel:
dpkg -l | grep linux-headers-$(uname -r)
If nothing appears, install the matching headers and rebuild the VirtualBox modules:
sudo apt install linux-headers-$(uname -r)
sudo /sbin/vboxconfig
Then verify the service is running:
systemctl status vboxdrv
Remove VirtualBox
If VirtualBox is no longer needed, remove it while preserving your virtual machine files. If you installed the Extension Pack, uninstall it first to clean up the proprietary components:
sudo vboxmanage extpack uninstall "Oracle VM VirtualBox Extension Pack"
To remove the package while keeping configuration:
sudo apt remove virtualbox-7.2
To remove VirtualBox completely including configuration files (while preserving virtual machines stored in ~/VirtualBox VMs), use purge:
sudo apt purge virtualbox-7.2 && sudo apt autoremove
If you also want to remove the VirtualBox repository and GPG key:
sudo rm /etc/apt/sources.list.d/virtualbox.sources /usr/share/keyrings/virtualbox.gpg
Optionally remove your account from the vboxusers group if you no longer need VirtualBox hardware access:
sudo gpasswd -d $USER vboxusers
Conclusion
Your Ubuntu system now runs a production-ready virtualization platform with full hardware access, automatic kernel module synchronization, and Oracle’s latest security patches through regular APT updates. You can create isolated virtual machines for testing, development, or cross-platform software evaluation without compromising your host system. The workflow is complete: VirtualBox runs on the host with Extension Pack enabling USB 3.0 and RDP features; inside each VM, Guest Additions delivers shared clipboard, drag-and-drop file transfers, shared folders, and automatic resolution scaling for efficient host-guest workflows. VirtualBox receives updates automatically as part of your regular system maintenance, keeping your virtualization environment current and secure.
perfect. thanks
amazing guide – the best I’ve seen
I would love you to add a section on how to install the guest additions in the guest os
I run into problems with installing guestadditions on the Arch VM
Thank you for this guide, it was clear and easy to follow. 🙂
Thank you for the accurate and easy-to-follow instructions.
I installed the stable version, not the nightly, but everything seems to work fine.