1.进入virtualbox官网
https://www.virtualbox.org/wiki/Downloads
2.点击Linux distributions
3.向下翻至如图
4.在/etc/yum.repos.d/目录下新建virtualbox.repo并写入如下内容
[virtualbox] name=Oracle Linux / RHEL / CentOS-$releasever / $basearch - VirtualBox baseurl=http://download.virtualbox.org/virtualbox/rpm/el/$releasever/$basearch enabled=1 gpgcheck=1 repo_gpgcheck=1 gpgkey=https://www.virtualbox.org/download/oracle_vbox.asc
5.更新yum缓存
yum clean all
yum makecache
6.安装virtualbox
yum install VirtualBox-5.1