Vagrant 2.2.6 無法使用VirtualBox 6.1解決辦法

      之前一直使用vagrant來管理VirtualBox的,結果前段時間VirtualBox被自動升到6.1了,然後在使vagrant up來啓動之前配置好的centos7的時候報瞭如下錯誤:
image.png

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,但是我發現官網上最新版就是2.2.6,和我本地裝的是一樣的。
於是我又嘗試重新初始化了一個centos8,使用vagrant up來啓動,結果竟然又報了一個新的錯誤:
image.png

PS G:\virtualBox\centos8> vagrant up
No usable default provider could be found for your system.

environments. Examples are VirtualBox, VMware, Hyper-V.

The easiest solution to this message is to install VirtualBox, which
is available for free on all major platforms.

If you believe you already have a provider available, make sure it
is properly installed and configured. You can see more details about
why a particular provider isn't working by forcing usage with
`vagrant up --provider=PROVIDER`, which should give you a more specific
error message for that particular provider.

提示我本地沒有可用的虛擬機,感覺瞬間就懵逼了,在控制面板中明明可以看到安裝的VirtualBox,感覺走進了死衚衕,萬幸的是天無絕人之路,在官網上還是找到了點蛛絲馬跡:
image.png
通過該鏈接點到vagrant在github上的倉庫,靈機一動去查看了issue,果然有人和我遇到了同樣的問題,並且神通廣大的網友給出瞭解決方案。
https://github.com/oracle/vagrant-boxes/issues/178
我參考上面的步驟進行了如下操作:

1.進入我的vagrant安裝目錄D:\HashiCorp\Vagrant(ps:默認安裝在c盤的這個目錄下,我安裝時只修改了盤符)
2.修改D:\HashiCorp\Vagrant\embedded\gems\2.2.6\gems\vagrant-2.2.6\plugins\providers\virtualbox\plugin.rb文件。在61行左右,添加
autoload :Version_6_1, File.expand_path("../driver/version_6_1", __FILE__)

image.png
記住使用管理權限修改。
3.修改D:\HashiCorp\Vagrant\embedded\gems\2.2.6\gems\ vagrant2.2.6\plugins\providers\virtualbox\driver\meta.rb文件,在66行左右增加"6.1" => Version_6_1,,修改後如下圖:

image.png

同時在當前目錄下新建version_6_1.rb文件,文件內容如下:

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

module VagrantPlugins
  module ProviderVirtualBox
    module Driver
      # Driver for VirtualBox 6.1.x
      class Version_6_1 < Version_6_0
        def initialize(uuid)
          super

          @logger = Log4r::Logger.new("vagrant::provider::virtualbox_6_1")
        end
      end
    end
  end
end

到這裏就結束了,然後嘗試啓動centos7,啓動成功:

image.png

總結:在我們使用一些開源工具的時候,如果遇到自己搞不定的問題時,可以去github上看看issue,也許有意外驚喜。

發佈了33 篇原創文章 · 獲贊 15 · 訪問量 11萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章