2 Ways to Install VirtualBox on Debian 9 Stretch

This tutorial shows you 2 ways to install VirtualBox on Debian 9 Stretch. VirtualBox is a free and open-source virtualization software that can run on Linux, Mac, Windows and Solaris. At the time of this writing, the latest stable version of VirtualBox is 5.2.10, released on April 17 2018. For some reason, it isn’t included in the default Debian 9 repository. You can install it from the upstream Oracle repository or the stretch-backports repository.

Some of the highlights in the VirtualBox 5.2.x series:

  • VM can be exported to Oracle Cloud (OPC).
  • Unattended guest installation
  • Added audio support for video recording

Note that the stretch-backports repository currently includes Virtualbox 5.1. If you want the latest version, use Oracle repository. If you have installed a previous version, then stop all running instances of virtual machines before installing the latest version. After the upgrade, it is recommended that you also upgrade the VirtualBox guest additions installed inside your virtual machines.

How to Install VirtualBox on Debian 9 Stretch From Oracle Repository

Open up a terminal window and run the command below to switch to the root user.

su -

Then run the following command to create a source list file for the Oracle VirtualBox repository. nano is a beginner-friendly command-line text editor.

nano /etc/apt/sources.list.d/virtualbox.list

install virtualbox on debian 9 stretch

You will be presented with the nano text editor. Add the following line into the file.

deb http://download.virtualbox.org/virtualbox/debian stretch contrib

debian 9 virtualbox

To save the file with nano text editor, you need to press CTRL+O, then press Enter. To exit nano text editor, press CTRL+X. Next, we need to download and import the Oracle GPG public key to Debian 9 system with the following command.

wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | apt-key add -

The public key allows APT package manager to verify the integrity of downloaded packages. Then all left to do is update local package index and install Virtualbox 5.2.

apt update

apt install virtualbox-5.2

Once it’s installed, start it from your application menu, or run the command below to start VirtualBox from terminal.

virtualbox

You can check the version number in help > about VirtualBox.

debiain 9 strectch virtualbox 5.2

To ensure that the VirtualBox host kernel modules (vboxdrv, vboxnetflt and vboxnetadp) are properly updated when the linux kernel version changes during the next apt upgrade, install the dkms package.

apt install dkms

How to Install VirtualBox on Debian 9 from strectch-backports Repository

The backports repository contains packages from testing and unstable branch that are recompiled on the stable branch. To enable stretch-backports, switch to root user and create a source list file.

su -

nano /etc/apt/sources.list.d/stretch-backports.list

Then add the following line to this file.

deb http://ftp.debian.org/debian stretch-backports main contrib

Save and close the file. Next, update the package index.

apt update

To install VirtualBox from stretch-backports repository, run the following command.

apt install -t stretch-backports virtualbox

Troubleshooting

Sometimes you may see the following error when starting a virtual machine.

rtr3initex failed with rc=-1912 (rc=-1912) the virtualbox kernel modules do not match this version of virtualbox

One of the cause is that you install virtualbox from stretch-backports repository and then install it again from Oracle repository. In that case, you need to completely remove one of them and install the other. For example, to completely remove the virtualbox from stretch-backports repository, run:

apt purge virtualbox

apt autoremove

Then run the following command to rebuild virtualbox kernel modules.

/sbin/vboxconfig

That’s it! I hope this tutorial helped you install VirtualBox on Debian 9 Stretch. As always, if you found this post useful, then subscribe to our free newsletter to get more tips and tricks.

Rate this tutorial
[Total: 63 Average: 4.8]

7 Responses to “2 Ways to Install VirtualBox on Debian 9 Stretch

  • Roger Hanna
    6 years ago

    Pretty sad when Virtualbox’s site instructions for Deb 9 and even Deb 9 site instructions are incorrect. You saved me a lot of time and very straighforward!

  • Did works fine for me on Debian 9.1, thanks a lot!

  • Barracuda777
    6 years ago

    thank you for the easy instruction, it worked perfectly!

  • andrew prasad
    6 years ago

    The following information may help to resolve the situation:

    The following packages have unmet dependencies:
    virtualbox : Depends: python3 (>= 3.6~) but 3.5.3-1 is to be installed
    Depends: python3.6 but it is not installable
    Depends: libgsoap-2.8.60 but it is not installable
    Depends: libpython3.6 (>= 3.6.4~rc1) but it is not installable

    • Xiao Guo-An (Admin)
      6 years ago

      Are you installing VirtualBox from stretch backports repo? I have no problem by using this method. You can install VirtualBox from Oracle repository instead.

  • thank you for this clear instruction. now i can run Oracle Virtualbox on my Debian 9.

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here