Fixing Vagrant When It Stops Responding on macOS Mojave

Vagrant not working on macOS 10.14 Mojave

* This page contains promotional content

I run vagrant on a Mac (Mojave), but recently I hit a situation where vagrant would not respond at all

$ vagrant ssh
$ vagrant status
$ vagrant info
$

No matter which command I type, there is no reaction whatsoever!?

Thinking that vagrant might be broken, I ran brew reinstall vagrant

After that the vagrant command came back, but this time I got the error below

$ 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? Is this a ruby related error??

VirtualBox 7.x does not support Mojave

Next I started VirtualBox, stopped the BOX used by vagrant, and updated VirtualBox to the latest 7.x. It turns out 7.x does not support Mojave and it would not even launch, so I went back to 6.x again

Something to do with ruby?

Searching based on the error, I found the article below

For now, I tried installing it with 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.

Touching the system ruby is scary, so I stopped here

Vagrant 2.3.1 and later do not support Mojave

On top of that, I also found an article saying that some versions of vagrant do not work on Mojave

$ vagrant --version
Vagrant 2.3.4

2.3.4 does not seem to work on Mojave, so this looks like the cause this time

Uninstalling vagrant and vagrant.rb

I worked through this by referring to the Github Issue

$ brew uninstall vagrant
$ brew install vagrant.rb

Replace /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask/Casks/vagrant.rb with the contents below

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

Installing 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!

By the way, if you install from a DMG instead of using homebrew, download and install it from (Vagrant v2.3.0 Binaries | HashiCorp Releases )

Now that 2.3.0 is installed, I tried running 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)'

The vagrant command came back safely and vagrant info and vagrant status became usable again, but a dependency error appeared

When I tried vagrant up

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

Uninstalling 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`

It looks like things are back to normal

Starting 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.

It looks like a warning about disk capacity, but there seems to be no problem for now, so I am leaving it alone

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:~$

Phew, it starts up again without any trouble

Things to watch out for with vagrant on Mojave

  • Do not upgrade to VirtualBox 7.x
  • Do not raise the vagrant version above 2.3.0
  • Do not update vagrant with brew

See also