{"record":{"id":"371e5fec64289edd","repo":"hashicorp/vagrant","slug":"the-box-you-re-attempting-to-add-already-exists-r","errorCode":null,"errorMessage":"The box you're attempting to add already exists. Remove it before\nadding it again or add it with the `--force` flag.\n\nName: %{name}\nProvider: %{provider}\nVersion: %{version}","messagePattern":"The box you're attempting to add already exists\\. Remove it before\nadding it again or add it with the `--force` flag\\.\n\nName: %(.+?)\nProvider: %(.+?)\nVersion: %(.+?)","errorType":"exception","errorClass":"Vagrant::Errors::BoxAlreadyExists","httpStatus":null,"severity":"error","filePath":"lib/vagrant/action/builtin/box_add.rb","lineNumber":428,"sourceCode":"        # @return [Box]\n        def box_add(urls, name, version, provider, md_url, env, **opts)\n          display_architecture = opts[:architecture] == :auto ?\n                                   Util::Platform.architecture : opts[:architecture]\n          env[:ui].output(I18n.t(\n            \"vagrant.box_add_with_version\",\n            name: name,\n            version: version,\n            providers: [\n              provider,\n              display_architecture ? \"(#{display_architecture})\" : nil\n            ].compact.join(\" \")))\n\n          # Verify the box we're adding doesn't already exist\n          if provider && !env[:box_force]\n            box = env[:box_collection].find(\n              name, provider, version, opts[:architecture])\n            if box\n              raise Errors::BoxAlreadyExists,\n                name: name,\n                provider: provider,\n                version: version\n            end\n          end\n\n          # Now we have a URL, we have to download this URL.\n          box = nil\n          begin\n            box_url = nil\n\n            urls.each do |url|\n              show_url = nil\n              if url.is_a?(Array)\n                show_url = url[1]\n                url      = url[0]\n              end\n","sourceCodeStart":410,"sourceCodeEnd":446,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/lib/vagrant/action/builtin/box_add.rb#L410-L446","documentation":"Errors::BoxAlreadyExists is raised during add_from_direct/add_from_metadata right before download: the box collection already contains the exact name+provider+version (and architecture) being added, and env[:box_force] (the --force flag) is not set.","triggerScenarios":"A provider for the box is determined and env[:box_force] is falsy; env[:box_collection].find(name, provider, version, opts[:architecture]) returns an existing box; the raise carries name, provider, version.","commonSituations":"Re-running a bootstrap script that calls 'vagrant box add' on every run; re-adding a box to update it (wrong mental model - add does not upgrade in place); CI caching a ~/.vagrant.d between jobs.","solutions":["Pass --force (env[:box_force]) to overwrite the existing box entry.","Remove the existing box first ('vagrant box remove NAME --provider P --box-version V') if you want a clean slate.","For updates, prefer 'vagrant box update' inside the project rather than re-adding.","In scripts, guard with 'vagrant box list' (or collection.find) before adding."],"exampleFix":"# before\nvagrant box add hashicorp/bionic64   # already installed -> BoxAlreadyExists\n\n# after\nvagrant box add --force hashicorp/bionic64\n\n# or remove then add\nvagrant box remove hashicorp/bionic64 && vagrant box add hashicorp/bionic64","handlingStrategy":"validation","validationCode":"# Same check BoxAdd performs, done by the caller\ncollection = env.box_collection\nif collection.find(name, provider, version, architecture)\n  # already present: force overwrite or skip\n  env[:box_force] = true\nend","typeGuard":"def box_installed?(collection, name, provider, version = nil, architecture = nil)\n  !collection.find(name, provider, version, architecture).nil?\nend","tryCatchPattern":"begin\n  env.cli(\"box\", \"add\", url)\nrescue Vagrant::Errors::BoxAlreadyExists => e\n  # e.extra_data[:name], [:provider], [:version]\n  env.cli(\"box\", \"add\", \"--force\", url)\nend","preventionTips":["Make bootstrap scripts idempotent: check 'vagrant box list' (or collection.find) before adding.","Use --force deliberately when re-adding to refresh a box; use 'vagrant box update' for in-place updates.","Give CI jobs isolated VAGRANT_HOME when parallel adds are unavoidable."],"tags":["vagrant","box-add","duplicate","idempotency"],"backgroundTag":"duplicate-resource","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}