110

I had installed VirtualBox but it started giving me problems. So I uninstalled it using:-

sudo apt-get remove virtualbox-\*
sudo apt-get purge virtualbox-\*

But when I reinstalled VirtualBox it again resumed to previous settings and started giving same problems. How can i completely remove VirtualBox from my laptop and then reinstall it such that it wont give same problem again?

terdon
  • 100,812

6 Answers6

129

Your problem : Virtual Box keeps its folder and settings in your home folder. Delete everything inside the folder.

Uninstall VirtualBox first.

sudo apt-get remove --purge virtualbox 

Run these commands to delete all virtual machines and settings and Virtual Hard Drives:

sudo rm ~/"VirtualBox VMs" -Rf
sudo rm ~/.config/VirtualBox/ -Rf

If you want to install it again. Run this command:

sudo apt-get install virtualbox

Additionally, check:

sudo ps aux | grep -i "vbox"

Kill any "ghost" processes you may think are relevant.

sudo pkill VBox*
Neil
  • 4,475
  • 3
  • 22
  • 34
  • After reinstalling virtual box by following your procedure it said that fedora was inaccesible so i just removed it. Has it been successfuly removed? – Manish Sakpal Nov 29 '15 at 05:30
  • @Manishsakpal yes it has. – Neil Nov 29 '15 at 08:52
  • it is giving error to . ? – Manish Sakpal Nov 29 '15 at 08:57
  • @Manishsakpal What error. you may want to try my answer again. – Neil Nov 29 '15 at 08:58
  • Error is:- rm: invalid option -- '.' Try 'rm --help' for more information. – Manish Sakpal Nov 29 '15 at 09:01
  • @Manishsakpal what command did you type in ? show me – Neil Nov 29 '15 at 09:04
  • the last command you told me to run – Manish Sakpal Nov 29 '15 at 10:41
  • @Manishsakpal you copyed the command from my comment and copyed the . at the end its just this command sudo rm ~/.config/VirtualBox/ -Rf read my answer there is no . at the end of the delete command – Neil Nov 29 '15 at 10:47
  • This finally worked for me. Had several different errors after updating VB and Ubuntu. I am on Ubuntu 18.10 – Dominofoe May 05 '18 at 12:32
  • You don't need sudo for the rm commands – Frederik Witte Nov 15 '18 at 09:55
  • 1
    Don't put commands with sudo rm online! Someone can mess up their system badly with that. – TetraDev Jul 14 '20 at 16:33
  • If like me you ended up here because you just want to remove it, you do not need to go through the process given in this answer. The error message comes from VM or vbox running as root, so you have to stop it as root. I used sudo htop, found the line (perl command that took 40% of cpu) and killed it. After that I have been able to do a sudo dpkg --remove --force-remove-reinstreq virtualbox-6.1 and sudo dpkg --purge virtualbox-6.1. Hope this can help! – jeannej Jun 02 '21 at 14:47
66
sudo apt-get remove virtualbox* --purge

Just try one command for remove all VM. Or perticulary one VM

sudo apt remove virtualbox virtualbox-5.0 virtualbox-4.*

After that, you maybe get some instruction which will already give there you just need to type on the command line. Then again run same above command.

jsingh
  • 887
37

First find installed package using below command :

sudo dpkg -l | grep virtualbox 

Then copy packages and remove using dpkg or apt-get as below :

sudo dpkg --purge <Packages>

--force-all optional

And also manually remove folder on home directory (~/"VirtualBox VMs").

Nullpointer
  • 1,161
  • 3
  • 15
  • 32
  • 4
    Honestly I thought apt would remove packages installed with dpkg, but it doesn't even show virtualbox as being installed. Surprised that in 18.04.1 this is not linked up properly. – pbhj May 19 '19 at 16:56
16

If you installed VirtualBox through the installer script, you can find the directory where it is installed by running

cat /etc/vbox/vbox.cfg

You can then run the uninstall script located in the install directory. Assuming it's installed to /opt/VirtualBox, run

sudo /opt/VirtualBox/uninstall.sh
sudo rm -rf /opt/VirtualBox/
Slim
  • 507
  • This is the correct answer when virtualbox is installed with the installer and not with debian packages. – roeland Feb 19 '20 at 09:21
  • Working fine with VirtualBox script like: VirtualBox-6.0.18-136238-Linux_amd64.run from: https://download.virtualbox.org/virtualbox/6.0.18/ Thanks – Indacochea Wachín Apr 11 '20 at 18:27
13

Open the terminal and type:

sudo apt remove virtualbox unity-scope-virtualbox ^virtualbox-

How to uninstall Oracle VirtualBox

If you installed VirtualBox from the Oracle website find your VirtualBox version as follows:

sudo apt install aptitude
aptitude search virtualbox\*

The latest version of VirtualBox that has Oracle VM VirtualBox on the same line with it is the package you have installed. If you have the latest version of Oracle VirtualBox installed, it is named virtualbox-5.1.

Verify that this version of Oracle VirtualBox is currently installed.

dpkg-query -s virtualbox-5.1    

Uninstall Oracle VirtualBox using a command that looks like this:

sudo apt remove VirtualBox-5.1  

If you have a different version of Oracle VirtualBox installed replace VirtualBox-5.1 in the above command with your VirtualBox version.

karel
  • 114,770
  • In my case just the first line did everything. No further commands were necessary. The package shown in dpkg-query isn't installed locally. – Chaim Eliyah Jan 05 '20 at 03:00
1

Your problem is not with VirtualBox, it is with your kernel. You appear to have somehow run into an issue which caused a mismatch.

Simply run sudo apt update && sudo apt install -f as you've been instructed by the system, and it should install the correct packages.

Once this is completed, I recommend rebooting (just to be safe, though it is not absolutely necessary), and then running sudo apt remove --purge *virtualbox* to remove VirtualBox and any related packages.

NB:

If you don't run sudo apt install -f, you're going to keep running into this problem with pretty much any package, as the package management system is left in a broken state until that issue is resolved.

RolandiXor
  • 51,541