macOSのMojave上のVagrantが反応しない

Vagrant not work on macOS 10.14 Mojave

* 本ページはプロモーションが含まれています

Mac(Mojave)上でvagrantを起動しているのですが、最近になって、vagrantが反応しない現象が起きた

$ vagrant ssh
$ vagrant status
$ vagrant info
$

コマンド打っても、何の反応もない!?

もしかするとvagrantが壊れたのかも?と、brew reinstall vagrant した

その後、vagrantコマンドは復活したものの、今度は下記のエラー

$ vagrant status
Traceback (most recent call last):
	2: from /opt/vagrant/embedded/gems/2.3.4/gems/vagrant-2.3.4/bin/vagrant:111:in `<main>'
	1: from /opt/vagrant/embedded/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require'
/opt/vagrant/embedded/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require': cannot load such file -- vagrant (LoadError)
	12: from /opt/vagrant/embedded/gems/2.3.4/gems/vagrant-2.3.4/bin/vagrant:111:in `<main>'
	11: from /opt/vagrant/embedded/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:147:in `require'
	10: from /opt/vagrant/embedded/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:158:in `rescue in require'
	 9: from /opt/vagrant/embedded/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:158:in `require'
/opt/vagrant/embedded/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:83:in `require': cannot load such file -- google/protobuf_c (LoadError)
~/vagrant ❯                                                        w

google/protobuf_c ? ruby関連のエラーなのかな??

VirtualBox 7.xはMojave未対応 

次に、VirtualBoxを起動し、vagrant用のBOXを停止し、VirtualBoxを最新の7.xに更新したところ、7.xはMojaveに対応していないらしく、起動すらしなかったので、再度、6.xに戻した

ruby絡み? 

エラーを基に、検索してみたところ下記の記事が見つかった

とりあえず、gemでインストールしてみる

$ gem install google-protobuf --version=3.9.2 --platform=ruby
Fetching: google-protobuf-3.9.2.gem (100%)
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory.

システムのrubyに手を加えるのは怖いので中断

Vagrant 2.3.1以上はMojave未対応 

更には、vagrantのバージョンによっては、Mojaveに対応していない記事も見つかった

$ vagrant --version
Vagrant 2.3.4

2.3.4はMojaveでは動作しないようなので、今回はこれが原因っぽい

vagrantのアンインストールとvagrant.rb 

Github Issueの記事を参考に作業

$ brew uninstall vagrant
$ brew install vagrant.rb

/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/vagrant.rbを下記の内容に置き換え

cask "vagrant" do
  version "2.3.0"
  #sha256 "65a5fee8bcfa4bbd3be444efbcd997110a49f5ccc1fffc4457c0110ab51adecb"
  # new since 2023-01-23: https://status.hashicorp.com/incidents/xbbwr755y78b
  sha256 "dfcb08ee37a197c091d0d13f52a4cf55b98d24466063934032530959259fcd89"

  url "https://releases.hashicorp.com/vagrant/#{version}/vagrant_#{version}_darwin_amd64.dmg",
      verified: "hashicorp.com/vagrant/"
  name "Vagrant"
  desc "Development environment"
  homepage "https://www.vagrantup.com/"

  livecheck do
    url "https://github.com/hashicorp/vagrant"
    strategy :git
  end

  pkg "vagrant.pkg"

  uninstall script:  {
              executable: "uninstall.tool",
              input:      ["Yes"],
              sudo:       true,
            },
            pkgutil: "com.vagrant.vagrant"

  zap trash: "~/.vagrant.d"
end

vagrantをインストール 

$ brew install vagrant
Running `brew update --auto-update`...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).

You have 21 outdated formulae and 2 outdated casks installed.

==> Downloading https://releases.hashicorp.com/vagrant/2.3.0/vagrant_2.3.0_darwi
######################################################################### 100.0%
==> Installing Cask vagrant
==> Running installer for vagrant; your password may be necessary.
Package installers may write to any location; options such as `--appdir` are ignored.
Password:
installer: Package name is Vagrant
installer: Installing at base path /
installer: The install was successful.
🍺  vagrant was successfully installed!

ちなみに、homebrewでなくDMGによるインストールする場合は、 (Vagrant v2.3.0 Binaries | HashiCorp Releases )にてダウンロードしてインストール

2.3.0がインストールされたので、vagrantを起動してみる

$ vagrant info
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-disksize (= 0.1.3)'

無事にvagrantのコマンドが復活し、vagrant infovagrant status も使えるようになったが、依存性のエラーが出た

vagrant up してみると

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

vagrant-vbguestをアンインストール 

$ vagrant plugin uninstall vagrant-vbguest
$ vagrant status
Current machine states:

default                   poweroff (virtualbox)

The VM is powered off. To restart the VM, simply run `vagrant up`

通常に戻ったようだ

vagrant起動 

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Checking if box 'ubuntu/bionic64' version '20210412.0.0' is up to date...
==> default: A newer version of the box 'ubuntu/bionic64' for provider 'virtualbox' is
==> default: available! You currently have version '20210412.0.0'. The latest is version
==> default: '20230425.0.0'. Run `vagrant box update` to update.
==> default: Clearing any previously set forwarded ports...
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
    default: Adapter 2: bridged
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Running 'pre-boot' VM customizations...
==> default: Disk cannot be decreased in size. 30720 MB requested but disk is already 40960 MB.

容量に関する警告みたいだが、現状問題ないようなので保留にする

vagrant ssh 

$ vagrant ssh
Welcome to Ubuntu 18.04.5 LTS (GNU/Linux 4.15.0-209-generic x86_64)

Last login: Thu Apr 27 13:39:39 2023
vagrant@server:~$

ふぅ、無事に起動再開した

Mojave上vagrantの注意事項 

  • VirtualBox 7.x にはアップグレードしない事
  • vagrantのバージョンは2.3.0より上げない事
  • brewでvagrantを更新しない事

See also