Troubleshooting (and solving) the Homestead’s error message on OS X: “A VirtualBox machine with the name ‘homestead’ already exists. Please use another name or delete the machine with the existing name, and try again.”

laravel-framework Being studying Laravel these days, I’ve been playing around with VMs, but despite the awesome guidance of Jeffrey Way, for some unknown reason I found myself with unusable Homestead Virtual Machines. The background environment is well known for those who are used to Laravel: Virtual Box, Vagrant, Homestead. Yeah, you already know that.

The point is, whenever I tried to sudo vagrant up, the following error appeared every time:

A VirtualBox machine with the name 'homestead' already exists. Please use another name or delete the machine with the existing name, and try again.

Yet I was sure I had no VM with that name, so nothing to rename nor delete. In fact, the folder ~/.vagrant.d/boxes contained a VM named laravel-VAGRANTSLASH-homestead, the one I was trying to up with no luck. Hm, strange.

Google didn’t help and nowhere on the Internet was I able to find hints on this. Since I’m using Homestead 2.0.6, I had a precompiled Vagrantfile put inside a Homestead folder, in turn inside my project’s root folder. Let’s check the content of that file. Line 10 says:

require_relative 'scripts/homestead.rb’.

Well, let’s try to open that file then. At line 12, we find:

vb.name = ‘homestead’.

Should we try to change the name of the VM maybe? Definitely. Any name will fit, since it’s just a temporary change. I changed this line to vb.name = ‘HOMESTEAD’, saved and sudo vagrant up:

$ sudo vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Setting the name of the VM: HOMESTEAD There was an error while executing `VBoxManage`, a CLI used by Vagrant for controlling VirtualBox. The command and stderr is shown below. Command: ["modifyvm", "9557e9ed-2619-43b7-b7ba-1e9dfa5cb629", "--name", "HOMESTEAD"] Stderr: VBoxManage: error: Could not rename the directory '/var/root/VirtualBox VMs/settler_default_1416790879859_317_1416968745369_91923' to '/var/root/VirtualBox VMs/HOMESTEAD' to save the settings file (VERR_ALREADY_EXISTS) VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component SessionMachine, interface IMachine, callee nsISupports VBoxManage: error: Context: "SaveSettings()" at line 2527 of file VBoxManageModifyVM.cpp

Ha-ha, bingo! So:

$ sudo -s
$ cd /var/root/VirtualBox\ VMs

…and, surprise, there was a folder named homestead. I was sure it was a leftover folder from a previous configuration, so, without any further hesitation:

$ rm -r homestead
$ exit

Now, back into the Homestead folder:

$ vi Vagrantfile to edit the vm.name variable to reflect its original value: homestead. Saved the file and:

$ sudo vagrant up for the last time, and everything went fine. :)

Advertisements