293

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.

7
  • I think I'm completely missing your point because the first thing that pops into my mind is sudo find / -name lucid32.box. Commented Apr 15, 2012 at 0:30
  • exactly what I did, but I must be missing something as I could not find lucid32.box using this exact command... Commented Apr 15, 2012 at 4:28
  • 3
    Perhaps it does not exist with that name. Wild card searches such as *.box maybe? (BTW, wouldn't the extension be .vbox?) Commented Apr 15, 2012 at 15:39
  • Yes you are right. The search should be for *.vbox and not *.box. Mystery solved. :-) Would you like to key in an answer so I could accept it? Thx! Commented Apr 18, 2012 at 2:01
  • 2
    @CalvinCheng: I think you're mistaken about it being just a .vbox image in a tar archive. It is indeed a tar archive, but it contains files like box-disk1.vmdk, box.ovf, and Vagrantfile. I don't know exactly how those are used to create the files that VirtualBox uses, but if you open VB's .vbox file you'll see it is just XML. I'm assuming Vagrant transforms its files (also a binary and XML file, plus Vagrantfile) into the XML and binary files used by VirtualBox. If you open the binary files, however, you'll see they're different, so it's not a simple matter of untarring and renaming.
    – iconoclast
    Commented Jun 21, 2012 at 20:58

8 Answers 8

435

As mentioned in the docs, boxes are stored at:

  • Mac OS X and Linux: ~/.vagrant.d/boxes
  • Windows: C:/Users/USERNAME/.vagrant.d/boxes
7
  • 1
    Ah. Thanks for the clarification. I must be blind to have missed out that explanation in the docs. Commented Apr 20, 2012 at 1:42
  • 1
    @manojlds: see my comment on the question re: the .vbox file. It's not the VM by itself, it's just an XML file.
    – iconoclast
    Commented Jun 21, 2012 at 21:02
  • 38
    You can also use the env var VAGRANT_HOME to specify the location of .vagrant.d, as in VAGRANT_HOME=D:\.vagrant.d (Yes, it works in Windows too).
    – Sven
    Commented Jan 17, 2014 at 14:24
  • 7
    in the C:\Users\{username}\.vagrant.d\boxes on windows, i found only the .vmdk file not the .box !!
    – Bilal
    Commented Aug 16, 2015 at 0:14
  • 1
    Broken link to the docs Commented Sep 28, 2021 at 8:32
86

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

5
  • 12
    Not sure why this was downvoted. The information about the destination of unsuccessful downloads was useful. Commented Feb 7, 2015 at 4:39
  • 1
    ~/.vagrant.d/boxes never stores the .box file itself, just it's contents. ~/.vagrant/tmp is used to store the .box temporarily whilst downloading but is deleted upon installation within Vagrant. Commented May 14, 2015 at 23:13
  • 1
    Third line (for Windows) should be %userprofile%\.vagrant.d\boxes Commented Jan 28, 2019 at 18:30
  • 2
    This answer is for the case that you actually care about your hard disk space.
    – kiltek
    Commented Jun 25, 2019 at 14:35
  • @kiltek Indeed! I just reclaimed 20 GB just from clearing out the vagrant.d/tmp folder. Commented Sep 13, 2022 at 23:38
52

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

0
21

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.

2
  • is it possible to like, zip or tar the subfolders in the boxes folder to create an installable box file? Commented Jun 26, 2015 at 17:18
  • @ThorSummoner Yes, but you may aswell let Vagrant handle it in that case, eg, via the vagrant package command: docs.vagrantup.com/v2/cli/package.html. Commented Jun 27, 2015 at 1:23
15

@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.

1
6

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

1
  • Does %userprofile%\.vagrant.d\boxes work then? %userprofile% expands to c:\users\{username} Commented Apr 23, 2017 at 19:24
3

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.

1

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.