Introduction / Why This Is Needed
VirtualBox is a free, powerful Type 2 hypervisor that allows you to run multiple guest operating systems (Windows, Linux, macOS, Solaris) on a single computer. Installing it on Ubuntu is a routine task, but it requires attention to detail, especially regarding kernel module compatibility. After completing this guide, you will have a fully functional virtual machine with USB support and other extensions.
Requirements / Preparation
Before you begin, ensure that:
- You have Ubuntu 22.04 LTS or newer installed (the instructions also work for recent versions of Debian).
- You have access to an account with sudo privileges.
- Your system is updated:
sudo apt update && sudo apt upgrade -y. - Important: The
dkms(Dynamic Kernel Module Support) package must be installed. It is usually present by default, but you can check with:dpkg -l dkms | grep -q dkms || echo "DKMS is not installed. Install it with: sudo apt install dkms"
Step-by-Step Guide
Step 1: Add the Official Oracle Repository
The Ubuntu repository often contains outdated versions of VirtualBox. Let's add the official source from Oracle.
- Import the Oracle GPG key:
wget -O- https://www.virtualbox.org/download/oracle_vbox_2016.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/virtualbox-archive-keyring.gpg > /dev/null - Add the repository to your system. For Ubuntu 22.04 (jammy) and 24.04 (noble):
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/virtualbox-archive-keyring.gpg] https://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list
Step 2: Update and Install VirtualBox
After adding the repository, install the main package and the package for working with kernel modules (dkms).
sudo apt update
sudo apt install virtualbox virtualbox-dkms -y
What happens:
virtualbox— the main package with the graphical interface and CLI.virtualbox-dkms— a critically important package. It automatically rebuilds kernel modules (vboxdrv,vboxnetflt, etc.) on every kernel update, preventing the "Kernel driver not installed" error.
Step 3: Install the Extension Pack
The Extension Pack adds support for USB 2.0/3.0, RDP, encryption, and other features. Download the latest version from the official website or install it via the command line.
# Download the latest Extension Pack (version may differ)
wget https://download.virtualbox.org/virtualbox/7.0.12/Oracle_VM_VirtualBox_Extension_Pack-7.0.12.vbox-extpack
# Install it. You will be asked if you accept the license agreement. Press Enter, then 'y'.
sudo VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-7.0.12.vbox-extpack
💡 Tip: Install the Extension Pack with the exact same version as your VirtualBox. Check the version with:
virtualbox --help | head -1.
Step 4: Configure User Permissions
To work with USB devices and some other features, your user must be a member of the vboxusers group.
sudo usermod -aG vboxusers $USER
Important: This change takes effect after you log out and log back in (or reboot). Without this, you won't be able to connect a USB flash drive or use certain settings.
Step 5: Verify the Installation
- Launch VirtualBox from the applications menu or with the
virtualboxcommand. - In the menu, select File -> Preferences -> Extensions. You should see the installed Extension Pack.
- Create a test virtual machine (e.g., with an Ubuntu ISO) and ensure it starts.
- Check that kernel modules are loaded:
The output should includelsmod | grep vboxvboxdrv,vboxnetflt,vboxnetadp, etc.
Verification of Results
A successful installation is confirmed by:
- Launching the VirtualBox graphical interface without errors.
- The presence of a default virtual machines folder path in File -> Preferences -> General.
- The presence of the Extension Pack entry in File -> Preferences -> Extensions.
- The ability to create and run a virtual machine.
- Working USB redirection (if the Extension Pack is installed).
Potential Issues
Error: "No access to /dev/vboxdrv" or "Kernel driver not installed (rc=-1908)"
Cause: Kernel modules are not loaded or the user is not in the vboxusers group.
Solution:
- Ensure you ran
sudo usermod -aG vboxusers $USERand have logged out/in. - Reinstall the DKMS modules:
sudo apt install --reinstall virtualbox-dkms sudo dpkg-reconfigure virtualbox-dkms - Force a module build:
sudo /sbin/vboxconfig
Error: "The VirtualBox kernel modules do not match this version of VirtualBox"
Cause: The versions of VirtualBox and virtualbox-dkms differ (often after a partial update).
Solution: Completely reinstall VirtualBox from a single source:
sudo apt purge virtualbox virtualbox-*
sudo apt install virtualbox virtualbox-dkms
Extension Pack Does Not Appear in the List
Cause: An Extension Pack of a different version is installed, or the license agreement was not accepted. Solution:
- Check the version:
VBoxManage --version. - Remove the old Extension Pack:
sudo VBoxManage extpack uninstall "Oracle VM VirtualBox Extension Pack". - Reinstall it, downloading the package with the exact same version.
3D Graphics Acceleration Issues in the Guest OS
Cause: Guest Additions are not installed or are incompatible. Solution: In the running virtual machine, open the menu Devices -> Insert Guest Additions CD image.... Inside the guest system (e.g., Ubuntu), run:
# For an Ubuntu/Debian guest system
sudo apt update
sudo apt install build-essential dkms linux-headers-$(uname -r)
sudo sh /media/cdrom/VBoxLinuxAdditions.run
Reboot the guest system.
DKMS Build Error: "module verification failed: signature and/or required key missing"
Cause: Kernel module signature verification is enabled (Secure Boot). Solution:
- Option 1 (simpler): Disable Secure Boot in your UEFI/BIOS.
- Option 2 (without disabling): On the first DKMS install/build, you will need to enter a MOK (Machine Owner Key) password that you set. After rebooting, the system will prompt you to enroll the key. Follow the on-screen instructions.