文系卒のWebエンジニアの成長と備忘録
エンジニア経験を生かして発信するメディアサイト

MacOS MojaveのVagrant up失敗の対処法

PC Programming

こんにちはYsです。
今日はMacOSをMojaveにしたら、 VirtualBoxやVagrant環境が壊れてしまった話とその対処法を書いていきます。

以下はエラーが起きる前の僕の開発環境になります。

VirtualBox 5.1.6
Vagrant 1.8.6 

先日、Laravelの勉強をしようと、自分のローカル環境を立ち上げようとしたら(vagrant up)以下のエラーが発生しました。

ys:MyVagrant dara$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'bento/centos-6.8' is up to date...
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["hostonlyif", "create"]

Stderr: 0%...
Progress state: NS_ERROR_FAILURE
VBoxManage: error: Failed to create the host-only adapter
VBoxManage: error: VBoxNetAdpCtl: Error while adding new interface: failed to open /dev/vboxnetctl: No such file or directory
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component HostNetworkInterfaceWrap, interface IHostNetworkInterface
VBoxManage: error: Context: "RTEXITCODE handleCreate(HandlerArg *)" at line 94 of file VBoxManageHostonly.cpp

GUI(Virtual Boxの管理画面)からの起動を試みたものの、やはり起動はせず。
以下のエラーで調べたところ、同じ事象の人がチラホラいました。

There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox.

根本的な原因は、現状のMacOS Mojaveの相性と以前のVirtual BoxとVagrantのバージョンが悪いために引き起こるものでした。

結論からやったこと

  1. Virtual Boxの再インストール
  2. Vagrantの再インストール

Virtual Boxの再インストール

以下のサイトから再インストールを行います。(一旦、最新版で行います)

赤枠の部分からインストール

Vagrantの再インストール

Virtual Boxを再インストールした状態で、再度環境を立ち上げるため(Vagrant up)
そしたら以下のエラー。

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.
Please install one of the supported versions listed below to use Vagrant:  4.0, 4.1, 4.2, 4.3 

どうやらVagrantの環境が古すぎるようなのでこちらも最新版をインストールします。

以下のサイトにいき、macOS版をインストール

インストール後、再度環境を立ち上げるために(Vagrant up)

ys:MyVagrant dara$ vagrant status
Vagrant failed to initialize at a very early stage:

The plugins failed to initialize correctly. This may be due to manual
modifications made within the Vagrant home directory. Vagrant can
attempt to automatically correct this issue by running:

  vagrant plugin repair

If Vagrant was recently updated, this error may be due to incompatible
versions of dependencies. To fix this problem please remove and re-install
all plugins. Vagrant can attempt to do this automatically by running:

  vagrant plugin expunge --reinstall

Or you may want to try updating the installed plugins to their latest
versions:

  vagrant plugin update

Error message given during initialization: Unable to resolve dependency: user requested 'vagrant-vbguest (= 0.15.1)'

プラグインの問題で、それをどうするのかを聞いてきました。
英語を読む限り、僕の環境下で起きたことはこれなので、こちらを行います

Or you may want to try updating the installed plugins to their latest
versions:
vagrant plugin update
vagrant plugin update

上記のコマンドを入力後、再度環境を立ち上げたところ、無事に起動しました!


環境を再インストールしました。
ただ、この環境の直し方はあくまで一時的だと思われます。

開発環境によっては、VirtualBoxやVagrantのバージョンが新しすぎると内部のプラグインが対応していなかったり、
オンライン学習の環境が用意しているバージョンと差異が出てしまうため、同じように進んでいるはずが、うまく動かないといった状況に陥る可能性があります。

一旦、僕の中では動きましたが、再度動かないといった事象に陥った時はOldバージョン(前のバージョン)で再インストールすることをお勧めします。

開発する上で再度同じような事象が発生することもあり得るので、その時はまた当ブログで更新します。

\記事のシェアをお願いします!/