88

I deleted a folder containing a running Vagrant box before realising it was still running.

How can I delete it from Vagrant (global-status) now?

I already removed the Virtualbox VM.

Jonas
  • 121,568
  • 97
  • 310
  • 388
mettjus
  • 2,938
  • 4
  • 24
  • 32
  • 1
    Whether the Vagrant VM is running or not doesn't matter (I recently found this out). Even if the VM is stopped, if you manually delete its files instead of running `vagrant destroy`, `vagrant global-status` will still report the "host state unknown" problem. – John Berberich Oct 23 '14 at 19:01

5 Answers5

204

To discard old boxes listed in vagrant global-status (eg. you deleted the folder containing the .vagrant dir from the filesystem) you just need to run:

vagrant global-status --prune

You might need to remove the Virtual Machine directly from your provider (VMWare, Virtualbox, ..) control interface.

mettjus
  • 2,938
  • 4
  • 24
  • 32
Jon Dowdle
  • 2,358
  • 1
  • 14
  • 6
  • I created the problem for myself in reverse: I deleted the VM's files from the provider, and also changed the Vagrantfile so that the VM was no longer part of the project's Vagrant configuration. The `--prune` option worked for my scenario as well. Thanks! – John Berberich Oct 23 '14 at 19:15
  • It worked for me only from inside an existing running Vagrant provisioned VM. – Nikos Alexandris Dec 28 '15 at 10:47
  • 2
    Didn't work for me. I had to manually edit `~/.vagrant.d/data/machine-index` and remove the offending entry. – Dalin Jan 19 '16 at 18:47
  • This worked for my case. If you change your machine name and the old one (that don't work anymore) still listed by vagrant global-status. – Dayron Gallardo Jan 31 '18 at 14:23
6

I believe that the new filename of the global data is ~/.vagrant.d.

So you can run rm -r ~/.vagrant.d to delete all user data for a fresh start.

kenorb
  • 155,785
  • 88
  • 678
  • 743
Alex Phelps
  • 393
  • 4
  • 8
0

For my case: Where kitchen and .kitchen/ folder may contain hidden vagrant files create by

$ kitchen create

I need to go further than either kitchen destroy or vagrant destroy or even vagrant destroy machineID ( from vagrant global-status - which gives a list of vagrant instances across your user space. )

In my case, I had to blow away the vagrant machine lock files contained in the users .vagrant hidden directory.

$ rm -r ~/.vagrant/data

And in my case I need to sudo the above command.

Then I finally got to a clean

$ vagrant global-status

list

rnevius
  • 26,578
  • 10
  • 58
  • 86
0

First you use vagrant global-status to list all the vagrant machines and their status and ids.

then you can use:

 vagrant destroy -f the_id_of_the_machine

after that if you run vagrant global-status again you will find that the id you have specified in the vagrant destroy -f command has been removed from the list.

and then you might need to restart your machine However these commands will not affect your boxes.

Amr Aly
  • 3,871
  • 2
  • 16
  • 33
0

The above commands didn't remove the old box in my case on a Windows machine. I had already removed the .vagrant folder and the box from the virtualbox provider folder but the box was still in the vagrant global-status list.

As mentioned in the comment given by a vagrant up command:

If you believe this message is in error, please check the process
listing for any "ruby" or "vagrant" processes and kill them. Then
try again.

So I killed ruby.exe from the process list and did a subsequent vagrant global-status --prune.

ulrich
  • 1,431
  • 3
  • 17
  • 46