First, follow the instructions in the official link:
https://www.virtualbox.org/wiki/Linux_Downloads
So, add one of the following lines according to your distribution to your /etc/apt/sources.list:
deb http://download.virtualbox.org/virtualbox/debian trusty contrib
deb http://download.virtualbox.org/virtualbox/debian saucy contrib
deb http://download.virtualbox.org/virtualbox/debian raring contrib
deb http://download.virtualbox.org/virtualbox/debian quantal contrib
deb http://download.virtualbox.org/virtualbox/debian precise contrib
deb http://download.virtualbox.org/virtualbox/debian lucid contrib non-free
deb http://download.virtualbox.org/virtualbox/debian wheezy contrib
deb http://download.virtualbox.org/virtualbox/debian squeeze contrib non-free
1) For Ubuntu 12.10, we add
deb http://download.virtualbox.org/virtualbox/debian quantal contrib
2) Downloading and registering Oracle public key for apt-secure:
wget -q http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc -O- | sudo apt-key add -
3) To install VirtualBox, do
sudo apt-get update
sudo apt-get install virtualbox-4.3
4) Ubuntu/Debian users might want to install thedkms package to ensure that the VirtualBox host kernel modules (vboxdrv,vboxnetflt andvboxnetadp) are properly updated if the linux kernel version changes during the next apt-get upgrade.
sudo apt-get install dkms
5) Start VirtualBox, there is a warnning:
root@Kitty:/home/aegis# virtualbox
WARNING: The vboxdrv kernel module is not loaded. Either there is no module
available for the current kernel (3.5.0-17-generic) or it failed to
load. Please recompile the kernel module and install it by
sudo /etc/init.d/vboxdrv setup
You will not be able to start VMs until this problem is fixed.
6) Run what it told me, another issue occurs:
root@Kitty:/home/aegis# sudo /etc/init.d/vboxdrv setup
Stopping VirtualBox kernel modules ...done.
Uninstalling old VirtualBox DKMS kernel modules ...done.
Trying to register the VirtualBox kernel modules using DKMSError! Your kernel headers for kernel 3.5.0-17-generic cannot be found.
Please install the linux-headers-3.5.0-17-generic package,
or use the --kernelsourcedir option to tell DKMS where it's located
...failed!
(Failed, trying without DKMS)
Recompiling VirtualBox kernel modules ...failed!
(Look at /var/log/vbox-install.log to find out what went wrong)
7) This time we install linux-headers-3.5.0-17-generic as it told me:
root@Kitty:/home/aegis# sudo apt-get install linux-headers-3.5.0-17-generic
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
linux-headers-3.5.0-17-generic
0 upgraded, 1 newly installed, 0 to remove and 473 not upgraded.
Need to get 946 kB of archives.
After this operation, 11.2 MB of additional disk space will be used.
Get:1 http://cn.archive.ubuntu.com/ubuntu/ quantal/main linux-headers-3.5.0-17-generic amd64 3.5.0-17.28 [946 kB]
Fetched 946 kB in 2s (404 kB/s)
Selecting previously unselected package linux-headers-3.5.0-17-generic.
(Reading database ... 142701 files and directories currently installed.)
Unpacking linux-headers-3.5.0-17-generic (from .../linux-headers-3.5.0-17-generic_3.5.0-17.28_amd64.deb) ...
Setting up linux-headers-3.5.0-17-generic (3.5.0-17.28) ...
Examining /etc/kernel/header_postinst.d.
run-parts: executing /etc/kernel/header_postinst.d/dkms 3.5.0-17-generic /boot/vmlinuz-3.5.0-17-generic
8) Run /etc/init.d/vboxdrv setup again:
root@Kitty:/home/aegis# sudo /etc/init.d/vboxdrv setup
Stopping VirtualBox kernel modules ...done.
Uninstalling old VirtualBox DKMS kernel modules ...done.
Trying to register the VirtualBox kernel modules using DKMS ...done.
Starting VirtualBox kernel modules ...done.
9) Start VirtualBox and it seems everything is fine:
root@Kitty:/home/aegis# virtualbox
root@Kitty:/home/aegis#