Downgrading Vagrant version

I ended up coming across this Composer could not find a composer.json file on ‘vagrant up’ issue and wanted to share at least a way to downgrade vagrant. Sharing here since that thread is closed.

I followed these stack overflow instructions. I think the other solution on the same thread might make even more sense, but if you are going for version 2.2.10, the below code added to a file named with an .rb extension and running brew install --cask the_file.rb should do the trick (once you have run brew remove vagrant.)

It’s basically just updating the git commit and sha256 numbers that the url the little script pulls from references.

cask "vagrant" do
  version "2.2.10"
  sha256 "913d959455d37a0bb410c89ba3aedc886ccc76ce06bae7b228ba7454294325da"

  url "https://releases.hashicorp.com/vagrant/#{version}/vagrant_#{version}_x86_64.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

2 Likes

For most recent version currently working on Big Sur, 2.2.18:

cask "vagrant" do
  version "2.2.18"
  sha256 "b4e8103aabdf29f18f592cd6de4fa03bf182fbc192a0757b5e18156cb18fa672"

  url "https://releases.hashicorp.com/vagrant/#{version}/vagrant_#{version}_x86_64.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

I believe the name of the file needs to match the cask name in the file header so: vagrant.rb.

I did something similar.

  1. Go to homebrew, search for package - vagrant — Homebrew Formulae

  2. Navigate to the cask code, then to the history for vagrant.rb - https://github.com/Homebrew/homebrew-cask/commits/a3e6f4f680dda5b96482e170a4c49e76be4abfd0/Casks/vagrant.rb

  3. Find the version you want; e.g. 2.2.18. Click ‘view at this point in time’, and confirm it has the version you want: homebrew-cask/vagrant.rb at 8bc9cb1bfabdfb65f50081de82b2abef42cf106e · Homebrew/homebrew-cask · GitHub

  4. Click the ‘raw’ button and copy the url, e.g. https://raw.githubusercontent.com/Homebrew/homebrew-cask/8bc9cb1bfabdfb65f50081de82b2abef42cf106e/Casks/vagrant.rb

  5. Use wget to fetch it (will save it to vagrant.rb in your current directory:

wget https://raw.githubusercontent.com/Homebrew/homebrew-cask/8bc9cb1bfabdfb65f50081de82b2abef42cf106e/Casks/vagrant.rb
  1. Install it: brew install --HEAD -s vagrant.rb (credit).

It’d be cool if trellis had a shortcut for installing Vagrant at a specific version though, but at least this is documented here in discourse.

2 Likes

This thread really shows that Homebrew isn’t a good choice for installing Vagrant. Look how hard they make it just to install an older version :frowning_face:

My suggestion: just download whatever version you need from Downloads | Vagrant by HashiCorp

It has a list of all old versions too and is a simple dmg installer which you can just install over any existing version. Personally I don’t worry about upgrading Vagrant either unless I actually notice something is wrong.

3 Likes

Great advice, as usual, Scott. Thank you. I forget how to mark this as a solution, but would like to.