【问题标题】:Box 'laravel/homestead' could not be found找不到框“laravel/宅基地”
【发布时间】:2016-04-29 01:27:57
【问题描述】:

我已经从here 手动下载了laravel/homestead 框。

我成功添加了盒子:

vagrant box add file:///path/to/the/laravel/homestead.box --name 'laravel/homestead'

但当我运行 vagrant up 时,它会显示:Box 'laravel/homestead' could not be found,即使 vagrant box list 显示该框。

下载页面显示运行vagrant init laravel/homestead 会生成vagrantfile,但laravel/homestead 存储库本身提供vagrantfile

我可以用vagrantfile 生成vagrant up vagrant init laravel/homestead,但它缺少laravel/homestead 存储库的vagrantfile 中的基本配置。

这是生成的vagrantfile

# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "laravel/homestead"

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  # config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
  # such as FTP and Heroku are also available. See the documentation at
  # https://docs.vagrantup.com/v2/push/atlas.html for more information.
  # config.push.define "atlas" do |push|
  #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
  # end

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   sudo apt-get update
  #   sudo apt-get install -y apache2
  # SHELL
end

它有这个设置:

Vagrant.configure(2) do |config|  
    config.vm.box = "laravel/homestead"
end

我尝试将此添加到默认的laravel/homesteadvagrantfile,但没有成功。

require 'json'
require 'yaml'

VAGRANTFILE_API_VERSION = "2"
confDir = $confDir ||= File.expand_path("~/.homestead")

homesteadYamlPath = confDir + "/Homestead.yaml"
homesteadJsonPath = confDir + "/Homestead.json"
afterScriptPath = confDir + "/after.sh"
aliasesPath = confDir + "/aliases"

require File.expand_path(File.dirname(__FILE__) + '/scripts/homestead.rb')

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    if File.exists? aliasesPath then
        config.vm.provision "file", source: aliasesPath, destination: "~/.bash_aliases"
    end

    if File.exists? homesteadYamlPath then
        Homestead.configure(config, YAML::load(File.read(homesteadYamlPath)))
    elsif File.exists? homesteadJsonPath then
        Homestead.configure(config, JSON.parse(File.read(homesteadJsonPath)))
    end

    if File.exists? afterScriptPath then
        config.vm.provision "shell", path: afterScriptPath
    end

    ## HERE I added the setting ############################################
    config.vm.box = "laravel/homestead"
    ########################################################################
end

我该怎么办?

【问题讨论】:

    标签: laravel vagrant vagrantfile homestead


    【解决方案1】:

    El-Capitan 操作系统

    流浪者 2.2.14

    虚拟机 6

    转到您的目录,例如:/user/(name)/Homestead/scripts

    这个目录是你进行 vagrant init 和其他安装过程的地方。

    使用 sublime text 或文本编辑器打开 homestead.rb 文件,然后更改以下内容:

    config.vm.box_version = settings['version'] ||= '‍‍‍‍‍~&gt; 9'

    config.vm.box_version = settings['version'] ||= '‍‍‍‍‍&gt;= 10.1.1'

    在此更改后,您可以在目录中启动您的 vagrant

    vagrant up
    

    将您的盒子导入 virtualbox 需要几分钟时间。

    【讨论】:

      【解决方案2】:

      对于遇到此问题的任何人,请确保您 upgrade your vagrant 并添加 laravel/homestead 应该可以顺利安装。

      【讨论】:

        【解决方案3】:

        如果你可以让 Vagrant 为你做这一切,为什么还要手动下载盒子?

        正如宅基地文档中所说:
        vagrant box add laravel/homestead 将为您添加和下载盒子。

        “如果此命令失败,您可能拥有需要完整 URL 的旧版本 Vagrant:”
        vagrant box add laravel/homestead https://atlas.hashicorp.com/laravel/boxes/homestead

        您可以像这样手动添加一个框:
        vagrant box add laravel/homestead path/to/your/box/file.box

        How to Install Manually Downloaded .box for Vagrant

        【讨论】:

        • 我的连接速度很慢
        • 旧版本的 vagrant 给我造成了这个问题。升级到最新和升级插件修复了一切。
        【解决方案4】:

        laravel/homstead project 提供的 Vagrantfile 比vagrant init 生成的通用 Vagrantfile 更高级

        laravel/homstead 项目提供的 Vagrantfile 使用了一些 ruby​​ 代码来协助设置 vagrant 环境。从homestead ruby code 中我们可以看到,它正在检查您是否有一个版本大于或等于 0.4.0 的框:

        config.vm.box_version = settings["version"] ||= "&gt;= 0.4.0"

        当您手动添加该框时,您会看到它存在于您的本地计算机上:

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

        请注意,提供商旁边的数字是 0。该数字是盒子版本。由于框是手动添加的,因此框元数据不可用,默认情况下您将获得版本 0。

        当您现在执行vagrant up 时,代码会检查您是否有一个 >= 0.4.0 的框,而您没有,这就是您得到Box 'laravel/homestead' could not be found 的原因。然后它会尝试下载所需的最低版本的盒子。

        为了规避这个问题,您可以在本地创建一个 metadata.json 文件,该文件与您下载的 box 文件位于同一目录中。例如:

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

        然后运行vagrant box add metadata.json

        这将安装带有版本的盒子,并且可以通过以下方式确认:

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

        您现在可以使用本地机器执行vagrant up

        【讨论】:

        • 非常感谢,我不能vagrant box add metadata.json所以我只是将homestead.rb中的box_version编辑为&gt;= 0
        • 谢谢,但我也认为我们需要小心在 metadata.json 文件中添加正确的版本。
        • 这正是我想要的。 2 年后,仍然是正确的答案,谢谢!
        【解决方案5】:

        我遵循了接受的答案,但它仍在尝试下载虚拟盒“盒子”。我不得不修改 scripts/homestead.rb 中的以下设置

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

        请注意,我已注释掉版本行,因为它抱怨以下消息:

        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.
        

        【讨论】:

          【解决方案6】:

          如果有人有同样的问题,用win,检查ms可视化库是否ok,主要是curl。

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

          【讨论】:

            【解决方案7】:

            我已经解决了这个问题。我只在 Mac El-capitan 上测试。

            vagrant box add laravel/homestead homestead.box
            

            它显示以下内容:

            ==> 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'!
            

            然后我改成了vagrant文​​件目录

            cd ~/.vagrant.d/
            

            然后列出文件,我看到了我的盒子

            cent   hashicorp-VAGRANTSLASH-precise64      laravel-VAGRANTSLASH-homestead
            

            并通过cd laravel-VAGRANTSLASH-homestead选择laravel

            和 ls 看看0

            我由mv 0 0.4.0指挥

            当我通过vagrant box list列出时

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

            然后我编辑 Vagrant Homestead 文件vi ~/Homestead/Vagrantfile 并添加以下内容:

            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
            

            然后vagrant up

            我希望它适用于无法直接通过 metadata.json 添加的一些人。谢谢。

            【讨论】:

            • 像魅力一样工作!但我还必须在“laravel-VAGRANTSLASH-homestead”目录中添加一个名为“metadata_url”的文件,其内容如下:“atlas.hashicorp.com/laravel/homestead”。
            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2017-04-24
            • 2016-03-30
            • 2016-04-17
            • 2019-06-15
            • 2015-12-09
            • 2015-02-28
            • 1970-01-01
            相关资源
            最近更新 更多