Vagrant+Virtualbox 踩坑 閃退&【No usable default provider could be found for your system.】

今天打算配置一個(gè)Vagrant+Virtualbox運(yùn)行環(huán)境,然而各種坑

1.下載Virtualbox

地址:https://www.virtualbox.org/wiki/Downloads
image.png

我安裝的是widows版本的
安裝好后直接運(yùn)行

1.下載Vagrant

地址:https://www.vagrantup.com/downloads.html
image.png

同樣是windows版本

安裝好后就開始入坑了

坑1 vagrant運(yùn)行

由于第一使用vagrant 之前看的教程也都是直接接輸入vagrant命令了,所以以為入口就是vagrant.exe
然后就是點(diǎn)擊vagrant.exe后各種閃退,閃退到懷疑人生。一波搜索,查到結(jié)果
vagrant正確的打開方式是通過cmd

image.png

輸入
vagrant --help

image.png

可以看到vagrant支持的命令
輸入
vagrant -v
查看版本號(hào)
image.png

坑2 windows命令

由于長(zhǎng)期的使用linux服務(wù)器滾瓜爛熟了linux命令,回到windows就是傻眼了,我的vagrant安裝在E盤,于是我想跳轉(zhuǎn)到E盤我的安裝目錄下去創(chuàng)建文件夾
于是我這樣做


image.png

然后沒有任何反應(yīng)
然后還有什么ll
這里說下正確的命令

1.進(jìn)入目錄直接輸入盤   如:  E:  然后回車
2.查看目錄下現(xiàn)有文件  dir 命令
3.創(chuàng)建新的文件夾  方法1   md +文件夾名   方法2   mkdir + 文件夾名稱
4.進(jìn)入目錄中的文件夾   cd 文件夾名
image.png

至于如果需要用到其他的命令就自己百度了我就不多說了
成功進(jìn)入vagrant目錄創(chuàng)建了新的文件夾vagrantCentos7后進(jìn)入第三坑

坑3 vagrant up

進(jìn)入目錄后
執(zhí)行 vagrant init centos/7


image.png

翻譯一下


image.png

這樣是正常的,可以看到目錄下就有一個(gè)Vagrantfile了,然后執(zhí)行vagrant up
然后就出現(xiàn)了一堆錯(cuò)誤提示


image.png

No usable default provider could be found for your system.

Vagrant relies on interactions with 3rd party systems, known as
"providers", to provide Vagrant with resources to run development
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.

又是一波各種查文檔,得到答案是版本的問題,但是沒有明確指出vagrant2.2.6可搭配virtualbox哪些版本
在一個(gè)https://blog.csdn.net/daxiang52/article/details/103518589
里得到了答案
vagrant2.2.6還沒有支持到virtualbox6.1
然后將6.1版的配置在里面,方法如下

1.找到vagrant目錄結(jié)構(gòu)的下的如下文件我安裝在E盤

E:\Vagrant\embedded\gems\2.2.6\gems\vagrant-2.2.6\plugins\providers\virtualbox\plugin.rb
在這個(gè)文件里增加6.1版本

require "vagrant"

module VagrantPlugins
  module ProviderVirtualBox
    class Plugin < Vagrant.plugin("2")
      name "VirtualBox provider"
      description <<-EOF
      The VirtualBox provider allows Vagrant to manage and control
      VirtualBox-based virtual machines.
      EOF

      provider(:virtualbox, priority: 6) do
        require File.expand_path("../provider", __FILE__)
        Provider
      end

      config(:virtualbox, :provider) do
        require File.expand_path("../config", __FILE__)
        Config
      end

      synced_folder(:virtualbox) do
        require File.expand_path("../synced_folder", __FILE__)
        SyncedFolder
      end

      provider_capability(:virtualbox, :forwarded_ports) do
        require_relative "cap"
        Cap
      end

      provider_capability(:virtualbox, :nic_mac_addresses) do
        require_relative "cap"
        Cap
      end

      provider_capability(:virtualbox, :public_address) do
        require_relative "cap/public_address"
        Cap::PublicAddress
      end

      provider_capability(:virtualbox, :snapshot_list) do
        require_relative "cap"
        Cap
      end
    end

    autoload :Action, File.expand_path("../action", __FILE__)

    # Drop some autoloads in here to optimize the performance of loading
    # our drivers only when they are needed.
    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

    module Model
      autoload :ForwardedPort, File.expand_path("../model/forwarded_port", __FILE__)
    end

    module Util
      autoload :CompileForwardedPorts, File.expand_path("../util/compile_forwarded_ports", __FILE__)
    end
  end
end
image.png

增加了一行

autoload :Version_6_1, File.expand_path("../driver/version_6_1", __FILE__)

2.找到同一目錄下的文件

E:\Vagrant\embedded\gems\2.2.6\gems\ vagrant2.2.6\plugins\providers\virtualbox\driver\meta.rb


image.png

image.png

增加

"6.1" => Version_6_1,
image.png

3.當(dāng)前目錄下新建version_6_1.rb文件,文件內(nèi)容如下:

image.png

內(nèi)容

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

然后從新打開cmd在剛剛創(chuàng)建的目錄行運(yùn)行vagrant up 就好了


image.png

完!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容