[virtual-machine] Where does Vagrant download its .box files to?

What happens to the .box file after the following command is executed?

vagrant box add lucid32 http://files.vagrantup.com/lucid32.box

I can't find the lucid32.box file on the file system after download has completed.

This question is related to virtual-machine virtualbox vagrant

The answer is


To change the Path, you can set a new Path to an Enviroment-Variable named: VAGRANT_HOME

export VAGRANT_HOME=my/new/path/goes/here/

Thats maybe nice if you want to have those vagrant-Images on another HDD.

More Information here in the Documentations: http://docs.vagrantup.com/v2/other/environmental-variables.html


On Windows, the location can be found here. I didn't find any documentation on the internet for this, and this wasn't immediately obvious to me:

C:\Users\\{username}\\.vagrant.d\boxes


The actual .box file is deleted by Vagrant once the download and box installation is complete. As mentioned in other answers, whilst downloading, the .box file is stored as:

~/.vagrant.d/tmp/boxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

where the file name is 'box' followed by a 40 byte hexadecimal hash. A temporary file on my system for example, is:

~/.vagrant.d/tmp/boxc74a85fe4af3197a744851517c6af4d4959db77f

As far as I can tell, this file is never saved with a *.box extension, which explains why the searches above failed to locate it. There are two ways to retrieve the actual box file:

  1. Download the .box file from vagrantcloud.com

    1. Find the box you're interested in on the atlas. For example, https://atlas.hashicorp.com/ubuntu/boxes/trusty64/versions/20150530.0.1
    2. Replace the domain name with vagrantcloud.com. So https://atlas.hashicorp.com/ubuntu/boxes/trusty64/versions/20150530.0.1 becomes https://vagrantcloud.com/ubuntu/boxes/trusty64/versions/20150530.0.1/providers/virtualbox.box.
    3. Add /providers/virtualbox.box to the end of that URL. So https://vagrantcloud.com/ubuntu/boxes/trusty64/versions/20150530.0.1 becomes https://vagrantcloud.com/ubuntu/boxes/trusty64/versions/20150530.0.1/providers/virtualbox.box
    4. Save the .box file
    5. Use the .box as you wish, for example, hosting it yourself and pointing config.vm.box_url to the URL. OR
  2. Get the .box directly from Vagrant

    This requires you to modify the ruby source to prevent Vagrant from deleting the box after successful download.

    1. Locate the box_add.rb file in your Vagrant installation directory. On my system it's located at /Applications/Vagrant/embedded/gems/gems/vagrant-1.5.2/lib/vagrant/action/builtin/box_add.rb
    2. Find the box_add function. Within the box_add function, there is a block that reads:

      ensure # Make sure we delete the temporary file after we add it, # unless we were interrupted, in which case we keep it around # so we can resume the download later. if !@download_interrupted @logger.debug("Deleting temporary box: #{box_url}") begin box_url.delete if box_url rescue Errno::ENOENT # Not a big deal, the temp file may not actually exist end end

    3. Comment this block out.
    4. Add another box using vagrant add box <boxname>.
    5. Wait for it to download. You can watch it save in the ~/.vagrant.d/tmp/ directory as a boxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX file.
    6. Rename the the file to something more useful. Eg, mv boxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX trusty64.box.

Why would you want this?

For me, this has been useful to retrieve the .box file so it can be hosted on local, fast infrastructure as opposed to downloading from HashiCorp's Atlas box catalog or another box provider.

This really should be part of the default Vagrant functionality as it has a very definitive use case.


On Windows 10 with Vagrant 2.2.2, setting the environment variable VAGRANT_HOME will ensure that boxes are downloaded to a subfolder of the folder specified for VAGRANT_HOME.

In my case I set VAGRANT_HOME to e:\vagrant_home, and the boxes get stored under e:\vagrant_home\boxes.

This works for me.

That's where the boxes are stored. The virtual machines are being created in the folder configured in Virtual Box. To set the VirtualBox VM storage folder, go to: VirtualBox GUI --> File --> Preferences --> General --> Default Machine Folder.


On Mac/Linux System, the successfully downloaded boxes are located at:

~/.vagrant.d/boxes

and unsuccessful boxes are located at:

~/.vagrant.d/tmp

On Windows systems it is located under the Users folder:

C:\Users\%userprofile%\.vagrant.d\boxes

Hope this will help. Thanks


@Luke Peterson: There's a simpler way to get .box file.

Just go to https://atlas.hashicorp.com/boxes/search, search for the box you'd like to download. Notice the URL of the box, e.g:

https://atlas.hashicorp.com/ubuntu/boxes/trusty64/versions/20150530.0.1

Then you can download this box using URL like this:

https://vagrantcloud.com/ubuntu/boxes/trusty64/versions/20150530.0.1/providers/virtualbox.box

I tried and successfully download all the boxes I need. Hope that help.


In addition to

Mac:
~/.vagrant.d/

Windows:
C:\Users\%userprofile%\.vagrant.d\boxes

You have to delete the files in VirtualBox/OtherVMprovider to make a clean start.


Examples related to virtual-machine

virtualbox Raw-mode is unavailable courtesy of Hyper-V windows 10 How to install Guest addition in Mac OS as guest and Windows machine as host How do I delete virtual interface in Linux? Bridged networking not working in Virtualbox under Windows 10 How to enable copy paste from between host machine and virtual machine in vmware, virtual machine is ubuntu VirtualBox: mount.vboxsf: mounting failed with the error: No such device What does the DOCKER_HOST variable do? VBoxManage: error: Failed to create the host-only adapter How to export a Vagrant virtual machine to transfer it installing vmware tools: location of GCC binary?

Examples related to virtualbox

virtualbox Raw-mode is unavailable courtesy of Hyper-V windows 10 VirtualBox Cannot register the hard disk already exists how to get the ipaddress of a virtual box running on local machine How to install Guest addition in Mac OS as guest and Windows machine as host How to connect to a docker container from outside the host (same network) [Windows] Failed to open/create the internal network Vagrant on Windows10 VT-x is disabled in the BIOS for both all CPU modes (VERR_VMX_MSR_ALL_VMX_DISABLED) VirtualBox: mount.vboxsf: mounting failed with the error: No such device Shared folder between MacOSX and Windows on Virtual Box Virtualbox shared folder permissions

Examples related to vagrant

vagrant primary box defined but commands still run against all boxes Psql could not connect to server: No such file or directory, 5432 error? Failed to open/create the internal network Vagrant on Windows10 Is there a default password to connect to vagrant when using `homestead ssh` for the first time? vagrant login as root by default How can I kill whatever process is using port 8080 so that I can vagrant up? Using Laravel Homestead: 'no input file specified' Error when trying vagrant up Vagrant ssh authentication failure Vagrant error : Failed to mount folders in Linux guest