{"record":{"id":"a85b6d7e6112895d","repo":"hashicorp/vagrant","slug":"a-virtualbox-machine-with-the-name-name-alrea","errorCode":null,"errorMessage":"A VirtualBox machine with the name '%{name}' already exists.\nPlease use another name or delete the machine with the existing\nname, and try again.","messagePattern":"A VirtualBox machine with the name '%(.+?)' already exists\\.\nPlease use another name or delete the machine with the existing\nname, and try again\\.","errorType":"exception","errorClass":"Vagrant::Errors::VMNameExists","httpStatus":null,"severity":"error","filePath":"plugins/providers/virtualbox/action/set_name.rb","lineNumber":37,"sourceCode":"          sentinel = env[:machine].data_dir.join(\"action_set_name\")\n          if !name && sentinel.file?\n            @logger.info(\"Default name was already set before, not doing it again.\")\n            return @app.call(env)\n          end\n\n          # If no name was manually set, then use a default\n          if !name\n            prefix = \"#{env[:root_path].basename.to_s}_#{env[:machine].name}\"\n            prefix.gsub!(/[^-a-z0-9_]/i, \"\")\n\n            # milliseconds + random number suffix to allow for simultaneous\n            # `vagrant up` of the same box in different dirs\n            name = prefix + \"_#{(Time.now.to_f * 1000.0).to_i}_#{rand(100000)}\"\n          end\n\n          # Verify the name is not taken\n          vms = env[:machine].provider.driver.read_vms\n          raise Vagrant::Errors::VMNameExists, name: name if \\\n            vms.key?(name) && vms[name] != env[:machine].id\n\n          if vms.key?(name)\n            @logger.info(\"Not setting the name because our name is already set.\")\n          else\n            env[:ui].info(I18n.t(\n              \"vagrant.actions.vm.set_name.setting_name\", name: name))\n            env[:machine].provider.driver.set_name(name)\n          end\n\n          # Create the sentinel\n          sentinel.open(\"w\") do |f|\n            f.write(Time.now.to_i.to_s)\n          end\n\n          @app.call(env)\n        end\n      end","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/plugins/providers/virtualbox/action/set_name.rb#L19-L55","documentation":"The SetName action derives a VM name (explicit config.vm.name, or '<folder>_<machine>_<ms>_<rand>' by default) and checks it against read_vms. If the name maps to a different VM UUID than the current machine, it raises VMNameExists — VirtualBox forbids two VMs with the same name in its registry.","triggerScenarios":"`vagrant up` when a VirtualBox VM with that name already exists under another UUID: a leftover VM from a crashed/destroyed environment, a manually created VM with the same config.vm.name, or a copied project directory reusing an explicit name.","commonSituations":"Explicit `config.vm.name = 'dev'` shared by two checkouts; a previous `vagrant destroy` that failed mid-way leaving the VM registered; VMs created by hand or by VirtualBox GUI with colliding names; restoring a project from backup while the old VM still exists.","solutions":["Delete the existing VM: `VBoxManage unregistervm '<name>' --delete` (or remove it in the VirtualBox GUI with 'Delete all files')","Or set a unique name: `config.vm.name = 'dev-2'` / rename your project directory when using default names","If the existing VM is actually this machine (stale .vagrant id), run `vagrant destroy -f` or remove the .vagrant/machines data so Vagrant re-adopts it","Check `VBoxManage list vms` to see the UUID currently holding the name before deleting anything valuable"],"exampleFix":"# before: two projects both do\nconfig.vm.name = 'devbox'\n\n# after (option A - unique names):\nconfig.vm.name = \"devbox-#{File.basename(Dir.pwd)}\"\n\n# after (option B - clear the collision on the host):\n# VBoxManage unregistervm \"devbox\" --delete && vagrant up","handlingStrategy":"validation","validationCode":"def vbox_name_free?(name, current_uuid = nil)\n  `VBoxManage list vms`.lines.none? do |l|\n    l =~ /^\"#{Regexp.escape(name)}\" \\{(.+)\\}$/ && Regexp.last_match(1) != current_uuid\n  end\nend\nabort 'VM name already registered' unless vbox_name_free?('devbox')","typeGuard":null,"tryCatchPattern":"begin\n  env.cli('up')\nrescue Vagrant::Errors::VMNameExists => e\n  warn \"Unregister '#{e.extra_data[:name]}' (VBoxManage unregistervm --delete) or set config.vm.name\"\nend","preventionTips":["Derive config.vm.name from the project directory or a per-user suffix","Run `vagrant destroy -f` at the end of CI jobs so names never linger","Periodically prune `VBoxManage list vms` entries your projects no longer own"],"tags":["virtualbox","vm-name","duplicate","naming"],"backgroundTag":"duplicate-vm-name","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}