12
votes

I have downloaded Homestead box thrid time this month by using vagrant box add laravel/homestead. I currently do not have access to fast internet so its pretty much annoying to download it everytime. Is there a way to use the downloaded package again and include the local package in vagrant , it dosent matters if projects or synced locations are preserved or not.

I am on Ubuntu machine if that matters.

Update : I need the downloaded Homestead box so that if my machine goes down or I have to install it somewhere else with no/slow internet connectivity , I can do it locally.

3
Usually once you use box add once you can just use vagrant init <box name> to create a new instance with that same base box. Why aren't you doing that? - benbot
@thecodethinker Maybe I couldn't explain it , I need the downloaded Homestead box so that if my machine goes down or I have to install it somewhere else with no/slow internet connectivity , I can do it locally. - Abhinav Gauniyal

3 Answers

17
votes

Oh that's pretty easy.

To pack up your currently installed box back into a .box file (while keeping it installed on your system) just use vagrant box list to find the box name, provider, and version.

Then use vagrant box repackage <name> <provider> <version> and it will pack it up into a file called package.box.

Hope This Helped !

15
votes

A better way to do it is :

  1. Just go to the directory where you have done the Vagrant init
  2. Do a vagrant package --output mynew.box

You will get the box packaged into the mynew.box file which you can even copy and share with your other developers. This is pretty useful in my opinion where you have slower internet speed.

3
votes

Just to complement @thecodethinker answer.

When I applied the suggested command:

vagrant box list

and

vagrant box repackage <name> <provider> <version>

The following happened:

Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'laravel/homestead' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0.4.0
==> default: Loading metadata for box 'laravel/homestead'
default: URL: https://atlas.hashicorp.com/laravel/homestead
==> default: Adding box 'laravel/homestead' (v0.5.0) for provider: virtualbox
default: Downloading: https://atlas.hashicorp.com/laravel/boxes/homestead/versions/0.5.0/providers/virtualbox.box

As you can see, it did not recognise the package.box and is trying to download from the internet. If you look closely above you can see that is looking for box version >= 0.4.0.

This is the result of vagrant box list:

laravel/homestead (virtualbox, 0)

Because the box was added manually. The box metadata was not available and by default it will set the version to 0.

To fix the problem, create a metadata.json:

{
"name": "laravel/homestead",
    "versions": [{
        "version": "0.4.0",
        "providers": [{
            "name": "virtualbox",
            "url": "file://package.box"
        }]
    }]
}

Because now we have a proper metadata, you can do:

vagrant box add metadata.json