Home CentOS How to Install VirtualBox in Different Linux Distributions

How to Install VirtualBox in Different Linux Distributions

Before installing Virtualbox, check if virtualization is enabled in BIOS. During bootup press the bios key and navigate through the bios option to enable/disable virtualization. Depending upon your machine product, the bios key may vary.

Now we will go through the installation process. In this article, our main focus is to install Virtualbox on Fedora/RHEL/CentOS, Ubuntu, and its derivate distributions. Virtualbox can be installed on several Linux operating systems which includes the following:

  • Ubuntu 18.04 LTS, 19.03 and 19.10
  • Debian GNU/Linux 9 (“Stretch”) and 10 (“Buster”)
  • Oracle Linux 6, 7 and 8
  • CentOS/Red Hat Enterprise Linux 6, 7 and 8
  • Fedora 30 and 31
  • Gentoo Linux
  • SUSE Linux Enterprise Server 12 and 15
  • openSUSE Leap 15.1

If your machine runs with Linux Kernel 2.6, 3.X, 4.X, and 5.X then you are good to install Virtualbox either using the VirtualBox installer or by doing a manual installation.

Virtualbox can be operated in two modes:

  1. Virtualbox GUI Manger
  2. Virtualbox headless mode

Virtualbox GUI manager gives a graphical interface for all the operations that you can do with Virtualbox. You can provision VM, allocate/modify resources, configure networks, take snapshots, clone your VM, and many more operations that can be performed through GUI manager with just a few clicks.

Before downloading and installing Virtualbox there are few dependent packages to be installed. In some distributions, these packages are shipped by default. We will install all the dependent packages before installing Virtualbox so there is no error thrown during the installation phase. For Ubuntu and its derivative, all the necessary packages are shipped with distribution so we can skip with prerequisites.

There are many ways to install Virtualbox in Linux but we will stick with a single method that is stable and can be easily ported. We are going to download the repo file, configure it and install VirtualBox.

Install VirtualBox in Debian, Ubuntu & Mint

Make sure your system is up to date and has the latest kernel version. You can install VirtualBox in any of the distributions based on Debian or Ubuntu. Run the following commands to add the repository.

$ wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add -
$ wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add -
$ sudo apt install software-properties-common
$ sudo add-apt-repository "deb [arch=amd64] http://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib”

Now run the update command to refresh the repository list.

$ sudo apt-get update

Install VirtualBox by running the following command.

$ sudo apt-get install virtualbox-6.1

Now launch VirtualBox from the application menu or from the terminal by running the following command.

$ virtualbox &

Install VirtualBox in Fedora, CentOS & RHEL

Make sure the system is up-to-date and running with the latest Linux kernel. You may encounter the following error due to kernel mismatch.

This system is currently not set up to build kernel modules.
Please install the Linux kernel "header" files matching the current kernel

To fix this you need to check and update your kernel to the latest version. Do this step before proceeding with all other steps.

# uname -r                     # Displays kernel release
# dnf update kernel-*          # RHEL 8/FEDORA
# yum update kernel-*          # RHEL 7/CENTOS 7

Reboot the system once the latest kernel is installed and choose the latest kernel from the boot loader menu. Once you logged into the system you can confirm if the kernel version matches with the kernel-devel version.

# uname -r                     # Displays kernel release
# rpm -q kernel-devel          # Displays devel version 

The initial step is to download the repo and install dependent packages. To download the repo run the following command.

-------- CENTOS/RHEL --------

# wget https://download.virtualbox.org/virtualbox/rpm/rhel/virtualbox.repo -P /etc/yum.repos.d/
# rpm --import https://www.virtualbox.org/download/oracle_vbox.asc

-------- Fedora --------
# wget http://download.virtualbox.org/virtualbox/rpm/fedora/virtualbox.repo -P /etc/yum.repos.d/
# rpm --import https://www.virtualbox.org/download/oracle_vbox.asc

Install EPEL repository. There are important dependent build packages in the EPEL repository.

-------- RHEL 8 --------

# dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

-------- CENTOS/RHEL 7 --------

# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Now refresh the repo list and install dependent packages.

-------- Fedora --------

# dnf update
# dnf install @development-tools
# dnf install kernel-devel kernel-headers dkms qt5-qtx11extras  elfutils-libelf-devel zlib-devel

-------- CENTOS/RHEL 7 --------

# yum update
# yum install binutils kernel-devel kernel-headers libgomp make patch gcc glibc-headers glibc-devel dkms -y

-------- RHEL 8 --------

# dnf update
# dnf install binutils kernel-devel kernel-headers libgomp make patch gcc glibc-headers glibc-devel dkms -y

Now go ahead and install VirtualBox by running the following command.

-------- FEDORA/RHEL 8 --------

# dnf install VirtualBox-6.1

-------- CENTOS/RHEL 7 --------

# yum install Virtualbox-6.1

Now launch VirtualBox from the application menu or from the terminal by running the following command.

# virtualbox &
Running VirtualBox in Linux
Running VirtualBox in Linux

NOTE: If you face any issue during installation you can check /var/log/vbox-install.log to debug what went wrong.

In the next article, we will take a look at installing the Fedora Cinnamon edition in VirtualBox.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

4 thoughts on “How to Install VirtualBox in Different Linux Distributions”

  1. Install VirtualBox? Why? The Linux kernel has had a native hypervisor (KVM) since 2007… so if you are running Linux, you *ALREADY* have a virtual machine hypervisor. You might need to install some userland tools but most all Linux distros package them in their stock repository. Try virt-manager. Try GNOME Boxes. Try cockpit and the cockpit-machines web-based GUI. Use the virsh command line. Easily manage remote VM hosts and the VMs they are running.

    Reply
    • Scott,

      I agree Linux has its own native hypervisor but there are many cases where people use two operating systems for different purposes. In my case, I use both Linux and Windows sometimes so I need something that is common to both the platform.

      Reply
    • ditto! and to add some weight in favor of KVM, here is my case. I know very well VirtualBox. For the last 5,6 years, I don’t need VM anymore, as Docker became more suitable for my work. Recently I need some VMs to practice Kubernetes at home. I was about to use VirtualBox b/c this is the only hypervisor I know.

      But I wanted to get up to date with 2021. I find out quickly that the hypervisor of choice for Linux is KVM.

      In case you have heard about the argument in favor of Virtualbox simplicity. It is debatable. You could do the same with Virt-Manager https://virt-manager.org/

      Only when you want to do more advanced stuff that KVM would require a heavier learning curve. This requires a bit of a learning curve. But once cleared, KVM + libvirt is far superior to Virtualbox in every aspect. Especially in terms of performance, scripting, and even automating the VM creation with cloud-init.

      Reply

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.