Vagrant:运行vagrant up命令时出现“必须指定一个盒子”的错误。

5
当尝试运行“vagrant up”终端命令时,我遇到了以下错误:
"There are errors in the configuration of this machine. Please fix the following errors and try again:
*A box must be specified."
在我的Homestead/.vagrant/machines/default/virtualbox文件夹中没有找到任何文件。所以我猜它提到的是必须指定一个box,但是这是我第一次使用Vagrant,我在网上搜索没有得到解决方法。
有人有解决办法吗?
编辑(Vagrantfile):
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
end
3个回答

6
在家目录下,您需要运行命令bash init.sh。这将在您的主目录(~)中生成Homestead.yaml文件(以及after.shaliases)。
如果您再次更改Homestead.yaml,则必须再次运行bash init.sh。它会询问是否覆盖,请选择是。
(另外,请确保folders:- map:目录存在)

但是bash init.sh命令不会覆盖homestead.yaml文件吗?这在我的机器上就是发生的事情。如果我编辑homestead.yaml文件并使用bash init.sh,我的更改将被还原。我是homestead的新手,正在尝试设置它,到目前为止没有成功。 - afaf12

3

我通过修复homestead.yaml中的文件路径来解决了这个问题。在终端进行安装时,会在主要的Homestead文件夹之外创建一个.homesetead文件夹,这就是导致问题的原因。但是,在将.homestead/homestead.yaml中的路径更改为与我的Homestead/homestead.yaml相同的路径后,问题不再存在。


-2

如果您正在使用homestead软件包,请使用homestead up而不是vagrant up。它已经知道所有文件的位置,可以轻松地提升您的虚拟机。


Homestead up 出现错误,提示找不到文件或目录。 - Lansana Camara

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接