9

I'm using versioned boxes, but not using Vagrant Cloud (I have a custom box host). Downloading versioned boxes works well.

However, when I'm developing new versions of my box locally, I don't want to have to go through an upload/download cycle every time I want to upgrade the version of the box loaded in Vagrant. In other words, I'd like to run vagrant box add, while specifying a newer version and a local file.

vagrant box add appears to have a option --box-version, but this is for constraining the version of a box being downloaded, not for specifying the version of a box being added. Attempting to specify box-version anyway results in:

You specified a box version constraint with a direct box file path. Box version constraints only work with boxes from Vagrant Cloud or a custom box host. Please remove the version constraint and try again.

But I'm not trying to constrain what I'm adding; I'm trying to specify. Any form of box add that works seems to set the version as 0. Is there any way to fix that and tell Vagrant what version I'm adding?

3 Answers3

6

Based on this answer, to specify a version for local boxes, you need to create a metadata.json.

The minimum content of the file looks like this:

{
    "name": "USERNAME/BOXNAME",
    "versions": [{
        "version": "X.Y.Z",
        "providers": [{
            "url": "package.box"
        }]
    }]
}

Where the package.box is the relative path from metadata.json

After that, you can simply run vagrant box add metadata.json to add a new box with a version.

Warning:

Vagrant stores the metadata.json url in the ~/.vagrant.d/boxes/FULLBOXNAME/metadata_url file. So, bee careful with names, you could't use the same name from different sources.

Senki
  • 186
2

after import your box file

cd ~/.vagrant.d/boxes/<username>-VAGANTSLASH-<boxname>/
mv 0 <specified version>

cdarlint
  • 121
0

You need to add provider name as "virtualbox", like

"providers": [{
        "name": "virtualbox",
        "url": ...