Box 'laravel/homestead' could not be found

て烟熏妆下的殇ゞ 提交于 2019-12-02 14:44:56
jaxim

The Vagrantfile provided by the laravel/homstead project is more advanced than a generic Vagrantfile that is generated by vagrant init

The Vagrantfile provided by the laravel/homstead project uses some ruby code to assist in setting up the vagrant environment. What we can see from the homestead ruby code is that it is checking that you have a box with a version greater than or equal to 0.4.0:

config.vm.box_version = settings["version"] ||= ">= 0.4.0"

As you added the box manually you will see that it is present on your local machine:

$ vagrant box list
laravel/homestead               (virtualbox, 0)

Note however the number next to the provider is 0. That number is the box version. As the box was added manually the box metadata was not available and by default you will get a version of 0.

When you now do a vagrant up the code is checking if you have a box >= 0.4.0 which you don't have so is why you are getting Box 'laravel/homestead' could not be found. It would then attempt to download the box at the minimal version required.

To circumvent around this you could create a metadata.json file locally in the same directory as your downloaded box file. e.g:

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

Then run vagrant box add metadata.json

This will install the box with a version and can be confirmed by:

$ vagrant box list
laravel/homestead               (virtualbox, 0.4.0)

You will now be able to perform vagrant up using your local box.

I have solved the problem by following. I test only on Mac El-capitan.

vagrant box add laravel/homestead homestead.box

it shows the following:

==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'laravel/homestead' (v0) for provider: 
    box: Unpacking necessary files from: file:///Users/lwinmaungmaung/Vagrant%20Boxes/Homestead/homestead.box
==> box: Successfully added box 'laravel/homestead' (v0) for 'virtual box'!

And then I changed to vagrant file directory

cd ~/.vagrant.d/

Then list files and I saw My boxes

cent   hashicorp-VAGRANTSLASH-precise64      laravel-VAGRANTSLASH-homestead

and choose to laravel by cd laravel-VAGRANTSLASH-homestead

and ls and see 0

I command by mv 0 0.4.0

When I list by vagrant box list

cent                (virtualbox, 0)
hashicorp/precise64 (virtualbox, 0)
laravel/homestead   (virtualbox, 0.4.0)

Then I edit Vagrant Homestead file vi ~/Homestead/Vagrantfile and add the following:

config.vm.box = "laravel/homestead"
config.vm.box_url = "https://atlas.hashicorp.com/laravel/homestead"
config.vm.box_version = "0.4.0"
config.vm.box_check_update = false

and then vagrant up

I hope it will works for some whose cannot add by metadata.json directly. Thanks.

if someone have the same probelm and useing win, check if ms visual libraries are ok, the main is curl.

https://www.microsoft.com/en-us/download/confirmation.aspx?id=5555

Why download the box manually, if you can let Vagrant do all that for you?

As said in the homestead documentation:
vagrant box add laravel/homestead will add and download the box for you.

"If this command fails, you may have an old version of Vagrant that requires the full URL:"
vagrant box add laravel/homestead https://atlas.hashicorp.com/laravel/boxes/homestead

You can add a box manually like so:
vagrant box add laravel/homestead path/to/your/box/file.box

How to Install Manually Downloaded .box for Vagrant

I followed the accepted answer but still it was trying to download the virtualbox "box". I had to modify the following settings in scripts/homestead.rb

#config.vm.box_version = settings["version"] ||= ">= 1.0.0"                 
config.vm.box_url = "file:///home/divick/Homestead/virtualbox.box"          

Note I have commented out the version line because it was complaining with the following message:

Bringing machine 'homestead-7' up with 'virtualbox' provider...
==> homestead-7: Box 'laravel/homestead' could not be found. Attempting to find and install...
    homestead-7: Box Provider: virtualbox
    homestead-7: Box Version: >= 1.0.0
==> homestead-7: Box file was not detected as metadata. Adding it directly...
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.

For anyone facing this issue, make sure you upgrade your vagrant and adding laravel/homestead should get installed without issues.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!