How To Install VirtualBox on CentOS 7 / RHEL 7

VirtualBox is an open-source hypervisor software that helps you create and run multiple guest operating systems (“virtual machines”) on a single hardware machine. VirtualBox can be installed on host operating systems, including Linux, Windows, Solaris, OS X, and OpenSolaris.

From version 2.0, VirtualBox supports 32 and 64bit host and guest operating systems. If you want to install 64bit guests, then your processor must support hardware virtualization, and, of course, the host operating system must be 64bit as well.

VirtualBox is released under GPL v2 and Oracle VM VirtualBox extension pack is released under PUEL (Personal Use and Evaluation License).

From VirtualBox 5.1, installers no longer rely on DKMS for module rebuilding.

This tutorial shows how to install VirtualBox on CentOS 7 / RHEL 7.

THIS DOCUMENT IS ALSO AVAILABLE FOR

Prerequisites

Update System

Update the system to the latest version.

yum update -y

Install Development Tools

Once the system is up, install header and development tools.

yum install -y kernel-devel kernel-headers gcc make perl

Also, install the wget package to download items using the terminal.

yum -y install wget

Reboot the system.

reboot

Install VirtualBox on CentOS 7 / RHEL 7

Set up VirtualBox repository

Download the Oracle public key.

wget https://www.virtualbox.org/download/oracle_vbox.asc

Import the Oracle public key.

rpm --import oracle_vbox.asc

Download the VirtualBox repository file for CentOS 7 / RHEL 7 and move it into /etc/yum.repos.d/ directory.

wget https://download.virtualbox.org/virtualbox/rpm/el/virtualbox.repo -O /etc/yum.repos.d/virtualbox.repo

OR

Create the /etc/yum.repos.d/virtualbox.repo file with the following repository information.

[virtualbox]
name=Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox
baseurl=https://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc

Install VirtualBox

Install VirtualBox using the yum command.

VirtualBox v6.0

yum install -y VirtualBox-6.0

VirtualBox v5.2

yum install -y VirtualBox-5.2

Run the below command to check the status of the VirtualBox Linux kernel module service.

systemctl status vboxdrv

Output:

 vboxdrv.service - VirtualBox Linux kernel module
   Loaded: loaded (/usr/lib/virtualbox/vboxdrv.sh; enabled; vendor preset: disabled)
   Active: active (exited) since Wed 2019-11-20 02:46:52 EST; 29s ago
  Process: 6389 ExecStart=/usr/lib/virtualbox/vboxdrv.sh start (code=exited, status=0/SUCCESS)
    Tasks: 0

Nov 20 02:46:52 centos7.itzgeek.local systemd[1]: Starting VirtualBox Linux k...
Nov 20 02:46:52 centos7.itzgeek.local vboxdrv.sh[6389]: vboxdrv.sh: Starting ...
Nov 20 02:46:52 centos7.itzgeek.local systemd[1]: Started VirtualBox Linux ke...
Hint: Some lines were ellipsized, use -l to show in full.

Access VirtualBox

Start VirtualBox: Application >> System Tools >> Oracle VM VirtualBox.

Start VirtualBox

OR

virtualbox

What are you waiting for? just go and create virtual machines.

VirtualBox 6.0 Running VMs on CentOS 7
VirtualBox 5.2 Running VMs on CentOS 7

Install Oracle VM VirtualBox Extension Pack

Oracle offers an extension pack to add additional functionalities such as USB 2.0/3.0, VirtualBox Remote Desktop Protocol (VRDP) support, Disk encryption, Host webcam passthrough, Intel PXE boot ROM, and PCI passthrough.

Please install the same version extension pack as your installed version of VirtualBox.

Download the Oracle VM VirtualBox extension pack using the wget command.

### VirtualBox 6.0 ###

cd /tmp

wget https://download.virtualbox.org/virtualbox/6.0.14/Oracle_VM_VirtualBox_Extension_Pack-6.0.14.vbox-extpack

### VirtualBox 5.2.22 ###

cd /tmp

wget https://download.virtualbox.org/virtualbox/5.2.34/Oracle_VM_VirtualBox_Extension_Pack-5.2.34.vbox-extpack

To install the extension pack, go to VirtualBox >> Preference >> Extensions >> browse for extension pack (/tmp) by clicking on the + icon.

Install VirtualBox Extension Pack

Click on the Install button to install the VirtualBox extension pack.

Accept the VirtualBox license to start the installation.

Conclusion

That’s All. You have successfully installed VirtualBox on CentOS 7 / RHEL 7. Please share your feedback in the comments section.

centos 7rhel 7virtualboxvirtualization
Comments (21)
Add Comment
  • Mr P

    I have problem with VirtualBox on CentOS7 running 3.10.0-123.6.3.el7.x86_64 kernel.

    # service vboxdrv setup
    Stopping VirtualBox kernel modules [ OK ]
    Uninstalling old VirtualBox DKMS kernel modulesldconfig: Can’t create temporary cache file /etc/ld.so.cache~: Permission denied
    ldconfig exited ungracefully
    ldconfig: Can’t create temporary cache file /etc/ld.so.cache~: Permission denied
    ldconfig exited ungracefully
    Error! There are no instances of module: vboxhost
    4.3.16 located in the DKMS tree.
    [ OK ]
    Trying to register the VirtualBox kernel modules using DKMSldconfig: Can’t create temporary cache file /etc/ld.so.cache~: Permission denied
    ldconfig exited ungracefully
    ldconfig: Can’t create temporary cache file /etc/ld.so.cache~: Permission denied
    ldconfig exited ungracefully
    [ OK ]
    Starting VirtualBox kernel modules [FAILED]
    (modprobe vboxdrv failed. Please use ‘dmesg’ to find out why)

    Any ideas?

    • Raj

      Dear P,

      Disable SELinux, that will solve your problems

      • Peter

        Dear Sir, how, In the World, can you tell the guy to disable the WHOLE!! SELinux system. Do you think it’s there for fun?

        • watzmann

          What you can do is to follow the suggestions of the SELinux message browser… all you have to do is to follow the steps described in the Details section… (i extended by the sudo command because this has to be done as root)

          Step 1
          sudo grep ldconfig /var/log/audit/audit.log | audit2allow -M mypol
          Step 2
          sudo semodule -i mypol.pp

          • B

            Or do:

            setenforce Permissive
            service vboxdrv setup
            setenforce Enforcing

  • Johnny

    Hi

    Thanks for the great tutorial again. Small question, can we install Virtualbox directly without the Gnome desktop ? To maybe get better performance…
    But, be able to have remote access to the virtualbox management.. ?

    Like is xrdp need a desktop to run on ? Or it can run over just a app ?

    Thanks again

    • Raj

      Hi Fourat,

      There is some issue in repo file,
      kindly add the following in virtualbox.repo

      [virtualbox]
      name=Oracle Linux / RHEL / CentOS-$releasever / $basearch – VirtualBox
      baseurl=https://download.virtualbox.org/virtualbox/rpm/el/7/x86_64/
      enabled=1
      gpgcheck=1
      gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc

  • George

    thanks a lot for this tutorial good one
    in step 5 its better to add it repo file manually because when i installed it there was a difference in baseurl
    Thanks

  • lucas

    Failed to install using DKMS, attempting to install without
    Makefile:183: *** Error: unable to find the sources of your current Linux kernel. Specify KERN_DIR= and run Make again. Stop.

    • Raj

      Dear Lucas,

      Reboot the machine as the yum update contains the latest kernel.
      You must run the
      service vboxdrv setup
      after rebooting.

  • jhon

    Starting VirtualBox kernel modules [FAILED]
    (Running VirtualBox in a Xen environment is not supported)

    HI I received the above error

    • Raj

      Dear John,

      Kindly use non xen kernel and re run setup

  • Eddy de Boer

    Thank you so much, worked like a charm!

  • Cesar Silence

    Thanks, work for me

  • nick gray

    great worked perfectly!! Thanks mate

  • ITzGeek Web

    Hi Ashok,

    Since the machine is not connected to the internet, you do not need to configure repo.

    Download the oracle_vbox.asc file to desktop and upload it to the server. Then use rpm –import oracle_vbox.asc to import.

    Download the latest vbox rpm.

    https://download.virtualbox.org/virtualbox/rpm/rhel/7/x86_64/VirtualBox-5.2-5.2.4_119785_el7-1.x86_64.rpm

    If you install VirtualBox with rpm command, it may tell you that there are some dependency errors. You need to fix that issue by downloading those (dependent) rpm from CentOS.

    Dependent rpm is different for each system. Mine is SDL and libvpx.

    Install all the dependent rpm one by one by downloading it from CentOS. Then finally install the VirtualBox.

      • ITzGeek Web

        Hi Ashok,

        Most of the dependencies are installed by default. Don’t give rpm -qpR command. This will list all dependencies irrespective of whether they are installed or not.

        Just use

        rpm -ivh virtualbox.rpm to install it.

        The above command will let you know the exact dependencies detail.

        Thanks.

    • Ashok

      Many Thanks! finally installed the dependent rpm and installation was successful.