Vagrant Box With This Name Already Exists

Due to the unique approach of Canonical to packaging vagrant boxes, the current ubuntu/xenial box has a hardcoded machine name which causes an error when you try to bring up a second VM using the same base box:

A VirtualBox machine with the name 'ubuntu-xenial-16.04-cloudimg' already exists.
Please use another name or delete the machine with the existing name, and try again.

There’s a stackoverflow question about this and a good answer (not the accepted one, the highest-voted one) which helped me a bit but it still wasn’t completely clear to me how to fix my problem and I had to dig about a bit.

EDIT: This is completely different to my original proposed solution, which actually broke other VMs! Do it this way instead …

The problem is that the box has been packaged with its name hardcoded in it – usually it’s better not to set the name of the box and let vagrant pick a name for it (usually the name of the directory, plus the date or something). The first VM you bring up will be fine but the second one will collide. To stop this happening, you need to manually name all of your boxes by doing something like this in your Vagrantfile:

  config.vm.provider "virtualbox" do |vb| = "myapp-database"

By setting the name for each box, we override their packaged name and correct the problem above.

Tangent: Ubuntu/Xenial Vagrant Box Has No Guest Additions

If you’re using this box then one of the other problems you will encounter is that it was packaged without the guest additions installed. Try the vagrant-vbguest plugin to fix that problem as well. You’re welcome :)

One thought on “Vagrant Box With This Name Already Exists

Leave a Reply

Please use [code] and [/code] around any source code you wish to share.

This site uses Akismet to reduce spam. Learn how your comment data is processed.