【解決方法】MacのOSをmojaveアップグレードしたらvagrantが動かなくなった時の対処

VagrantMac
【解決方法】MacのOSをmojaveアップグレードしたらvagrantが動かなくなった時の対処
Memo

MacのOSをmojaveアップグレードしたらvagrantが動かなくなってしまったため
解決のための手順をメモしました。

環境

  • Mac 10.14
  • Vagrant 2.0.3
  • virtualbox 5.2.12 r122591

発生したエラー

$ vagrant up
==> vagrant: A new version of Vagrant is available: 2.1.5!
==> vagrant: To upgrade visit: https://www.vagrantup.com/downloads.html

Bringing machine 'default' up with 'virtualbox' provider...
==> 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

解決方法

virtualboxの 元のバージョン 5.2.12 r122591

アップデート後のバージョン 5.2.18 r124319

手順

virtualboxをアンインストール

terminal
$ brew cask uninstall virtualbox

virtualboxを再インストール

terminal
$ brew cask install virtualbox

ここでまたエラー

xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
Error: Failure while executing; `git config --local --replace-all homebrew.private true` exited with 1.

xcode-selectをインストール

terminal
$ xcode-select --install

virtualboxを再インストール

terminal
$ brew cask reinstall virtualbox

無事インストール完了

installer: Package name is Oracle VM VirtualBox
installer: Installing at base path /
installer: The install was successful.
🍺  virtualbox was successfully installed!

再び vagrant up して無事成功しました。

terminal
$ vagrant up ... ==> default: Checking for guest additions in VM... ==> default: Configuring and enabling network interfaces... default: SSH address: 127.0.0.1:2222 default: SSH username: vagrant default: SSH auth method: private key ==> default: Exporting NFS shared folders... ==> default: Preparing to edit /etc/exports. Administrator privileges will be required... ==> default: Mounting NFS shared folders... ==> default: Mounting shared folders... default: /vagrant => /Users/yuki.hayakawa/workspace/sakura ==> default: Machine already provisioned. Run `vagrant provision` or use the `--provision` ==> default: flag to force provisioning. Provisioners marked to run always will still run.