I deleted the directory that contained the .vagrant file. When I up a new VM it's complaining about ports being in use. So how do I destroy a VM without having it's .vagrant file?
Asked
Active
Viewed 4.7k times
63
-
A problem shared is a problem halved: Did exactly the same dumb problem, immediately resolved thanks to SO once again... – Benjamin R May 01 '17 at 21:37
4 Answers
98
The following VirtualBox commands might help. If poweroff doesn't work, try unregistervm.
$ VBoxManage list runningvms
$ VBoxManage controlvm <uuid> poweroff
$ VBoxManage unregistervm <uuid>
Shell script to stop all running vms:
VBoxManage list runningvms | awk '{print $2;}' | xargs -I vmid VBoxManage controlvm vmid poweroff

Pickels
- 33,902
- 26
- 118
- 178
-
4These commands certainly destroy the VM. But they still leave an entry for the machine in "vagrant global-status". – Markus Miller Nov 03 '14 at 14:51
-
38@ValkoSipuli Try `vagrant global-status --prune`. See http://stackoverflow.com/a/24446866/300836 – Matt Gibson Dec 28 '14 at 10:54
-
1In my case, I used a slight variation: `VBoxManage list vms; VBoxManage discardstate
; VBoxManage unregistervm – nshew13 Jan 18 '15 at 14:56` -
4Use `vboxmanage unregistervm --delete` to physically delete the VM like with `vagrant destroy` – ens Nov 08 '16 at 16:35
31
Easiest thing to do is just launch the GUI client of VirtualBox and remove (possibly after shutting down) the virtual machine. You can just right click the virtual machine and perform these actions.

Gerry
- 6,012
- 21
- 33
-
4Not if you are ssh'd into your dev box or only work from the command line. Also if you `alias killvms="VBoxManage list runningvms | awk '{print \$2;}' | xargs -I vmid VBoxManage controlvm vmid poweroff"` you only need to type killvms instead of launching and waiting for the GUI. – Pickels Apr 01 '13 at 17:03
-
I assume typically developers work with Vagrant on their local machine and still run a GUI somewhere in the background :) – Gerry Apr 01 '13 at 17:40
-
2Your assumption was wrong! But since you live so close to me I'll let this one slide. Hihi, just kidding it's still a good answer for people running vagrant locally. – Pickels Apr 01 '13 at 18:30
7
The following bash function would poweroff and destroy all files related to all VMs for the current user:
function killvms() {
VBoxManage list runningvms | awk '{print $2;}' | xargs -I vmid VBoxManage controlvm vmid poweroff
VBoxManage list vms | awk '{print $2;}' | xargs -I vmid VBoxManage unregistervm --delete vmid
}
Add it to your ~/.bash_aliases
and call it in your shell via killvms
.

PowerKiKi
- 4,539
- 4
- 39
- 47
0
If you removed the VM using the GUI and you're still getting the error, you may try to delete the named VM from "%userprofile%\VirtualBox VMs". This worked for me

AmazingTurtle
- 1,187
- 1
- 15
- 31