{"record":{"id":"48f175e1ff7b0703","repo":"hashicorp/vagrant","slug":"the-box-you-re-attempting-to-add-already-exists-r-48f175","errorCode":null,"errorMessage":"The box you're attempting to add already exists. Remove it before adding 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 adding 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/box_collection.rb","lineNumber":95,"sourceCode":"    #   the box represents will be added.\n    # @param [Boolean] force If true, any existing box with the same name\n    #   and provider will be replaced.\n    def add(path, name, version, **opts)\n      architecture = opts[:architecture]\n      providers = opts[:providers]\n      providers = Array(providers) if providers\n      provider = nil\n\n      # A helper to check if a box exists. We store this in a variable\n      # since we call it multiple times.\n      check_box_exists = lambda do |box_formats, box_architecture|\n        box = find(name, box_formats, version, box_architecture)\n        next if !box\n\n        if !opts[:force]\n          @logger.error(\n            \"Box already exists, can't add: #{name} v#{version} #{box_formats.join(\", \")}\")\n          raise Errors::BoxAlreadyExists,\n            name: name,\n            provider: box_formats.join(\", \"),\n            version: version\n        end\n\n        # We're forcing, so just delete the old box\n        @logger.info(\n          \"Box already exists, but forcing so removing: \" +\n          \"#{name} v#{version} #{box_formats.join(\", \")}\")\n        box.destroy!\n      end\n\n      with_collection_lock do\n        log_provider = providers ? providers.join(\", \") : \"any provider\"\n        @logger.debug(\"Adding box: #{name} (#{log_provider} - #{architecture.inspect}) from #{path}\")\n\n        # Verify the box doesn't exist early if we're given a provider. This\n        # can potentially speed things up considerably since we don't need","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/lib/vagrant/box_collection.rb#L77-L113","documentation":"BoxAlreadyExists is raised inside the check_box_exists lambda in BoxCollection#add (lib/vagrant/box_collection.rb:95) when find() locates an existing box with the same name/provider/version and opts[:force] is not set. With --force the code instead logs and destroys the old box directory before continuing.","triggerScenarios":"'vagrant box add' (or a re-run of it / automation script) for a name+provider+version tuple that already exists under the collection directory; find(name, box_formats, version, box_architecture) returns a Box and the force flag is absent, so the error is raised with the colliding name, provider list and version.","commonSituations":"Re-running provisioning pipelines that add the same box twice; upgrading a box by re-adding the same version; multiple developers' bootstrap scripts adding a shared internal box.","solutions":["Pass --force to overwrite: 'vagrant box add <src> --name <n> --force' (the source shows the old box is destroyed first)","Or remove the existing entry: 'vagrant box remove <name> --provider <p> [--box-version <v>]', then add again","In scripts, make the add conditional: skip when 'vagrant box list' already shows the name/provider/version you need"],"exampleFix":"# before\nvagrant box add ./mybox.box --name corp/mybox\n\n# after\nvagrant box remove corp/mybox --provider virtualbox\nvagrant box add ./mybox.box --name corp/mybox\n# or simply\nvagrant box add ./mybox.box --name corp/mybox --force","handlingStrategy":"validation","validationCode":"existing = collection.find(name, [provider], version)\ncollection.add(path, name: name, provider: provider, version: version, force: existing.nil?)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make bootstrap scripts idempotent: skip 'vagrant box add' when 'vagrant box list' already shows the tuple","Pass --force only when overwriting is intended; it destroys the existing box directory first"],"tags":["vagrant","box","duplicate","idempotency","cli"],"backgroundTag":"duplicate-resource-exists","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}