There are a couple of ways to install VirtualBox 4.0. You can download the .deb file andinstall it manually. However, that will leave your installation outdated when new versions arrive. So, we are going to do it the other way by using the VirtualBox repository.
Oracle maintains a repository for VirtualBox. So, the first thing we are going to do is add the repository. Open the Terminal (or Konsole in Kubuntu) and execute the following command:
sudo nano /etc/apt/sources.list
You can use any text editor in place of nano.
Then, add the line given below to the file (source.list) opened in a separate line, and then save and close it.
deb http://download.virtualbox.org/virtualbox/debian maverick contrib
You have to replace maverick with the appropriate name if you are on another Ubuntu version. However, I am on Maverick and do not which other versions are supported.
After that you have to download the Oracle public key and add it. To do that execute the two commands below in the Terminal.
wget http://download.virtualbox.org/virtualbox/debian/oracle_vbox.asc
sudo apt-key add oracle_vbox.asc
Before we start the installation, you have to remove VirtualBox 3.2 if you have installed it. Execute the command below to do it.
sudo apt-get remove virtualbox-3.2
After that it is the usual update and install.
sudo apt-get update
sudo apt-get install virtualbox-4.0
http://digitizor.com/2011/01/07/virtualbox-4-0-install-ubuntu/