常见问题 您现在的位置是:首页 > 常见问题

Vagrant 2.2.6不能使用VirtualBox 6.1的解决办法

来源: 发布时间:2020-01-13 最后更新:2020-01-13 1629已围观

摘要最近在学lavarel,推荐Homestead,结果学习这个环境搭建的时候,报了个错,一直到网上找到了解决方案,mark一下。也放下一个版本就解决了,那也放在网上留存一下。

一直按网上的教程,下载了box文件,add了,但是在 vagrant up 的时候,报错了,错误信息如下:

The provider 'virtualbox' that was requested to back the machine
'default' is reporting that it isn't usable on this system. The
reason is shown below:

Vagrant has detected that you have a version of VirtualBox installed
that is not supported by this version of Vagrant. Please install one of
the supported versions listed below to use Vagrant:

4.0, 4.1, 4.2, 4.3, 5.0, 5.1, 5.2, 6.0

A Vagrant update may also be available that adds support for the version
you specified. Please check www.vagrantup.com/downloads.html to download
the latest version.

大概意思就是vagrant检测到系统安装了virtualbox,但是不能用,原因就是它只支持列出来的那些版本。还给了一个网址,啥用没有。最后还是在CSDN上找到了答案。不过想信,2.2.7版本肯定会解决这个问题,而且不久就会推出。


解决办法:

用管理员权限修改,否则你改不了。我用的是NotePad++,它在保存的时候会提示改用管理员权限。


1、修改plugin.rb文件。我的这个文件在
C:\HashiCorp\Vagrant\embedded\gems\2.2.6\gems\vagrant-2.2.6\plugins\providers\virtualbox
目录下,如果你安装在了别的盘,就去你的vagrant安装目录找。在6.0版本的下边,手工加上6.1,改好后如下:

module Driver
  autoload :Meta, File.expand_path("../driver/meta", __FILE__)
  autoload :Version_4_0, File.expand_path("../driver/version_4_0", __FILE__)
  autoload :Version_4_1, File.expand_path("../driver/version_4_1", __FILE__)
  autoload :Version_4_2, File.expand_path("../driver/version_4_2", __FILE__)
  autoload :Version_4_3, File.expand_path("../driver/version_4_3", __FILE__)
  autoload :Version_5_0, File.expand_path("../driver/version_5_0", __FILE__)
  autoload :Version_5_1, File.expand_path("../driver/version_5_1", __FILE__)
  autoload :Version_5_2, File.expand_path("../driver/version_5_2", __FILE__)
  autoload :Version_6_0, File.expand_path("../driver/version_6_0", __FILE__)
  autoload :Version_6_1, File.expand_path("../driver/version_6_1", __FILE__)
end


2、修改
C:\HashiCorp\Vagrant\embedded\gems\2.2.6\gems\ vagrant2.2.6\plugins\providers\virtualbox\driver\meta.rb
文件,其实就在上边目录的driver子目录中。在第66行,添加对6.1的支持,改好后如下:

driver_map   = {
  "4.0" => Version_4_0,
  "4.1" => Version_4_1,
  "4.2" => Version_4_2,
  "4.3" => Version_4_3,
  "5.0" => Version_5_0,
  "5.1" => Version_5_1,
  "5.2" => Version_5_2,
  "6.0" => Version_6_0,
  "6.1" => Version_6_1,
}


3、最后,在本目录中添加 version_6_1.rb 文件,你可以复制5.1的文件,然后按下边的内容去改,也可以直接复制文件内容如下:

require File.expand_path("../version_6_0", __FILE__)

module VagrantPlugins
  module ProviderVirtualBox
    module Driver
      # Driver for VirtualBox 6.1.x
      class Version_6_1 

会Ruby的朋友已经明白了,不会的也能猜出来了,我就是那个不会来猜的,哈哈哈。大概就是继承了6.0的配置文件,然后版本是6.1,日志文件也改一下名。


然后再去 vagrant up,就成功了。

很赞哦! (383)


站点信息

  • 网站平台ThinkCMF 5.1.5
  • PHP版本:7.3.31
  • QQ交流群: 惠达浪技术交流