The techniques herein have been ported from the fantastic blog post located here

Cask file

You can modify a cask file so it will force brew to install an older version of a package

# List installed packages
brew cask list

# Edit Cask file
brew cask edit <PackageName>

# e.g. Edit Ansible Cask file
brew cask edit ansible

The command might not work if you already removed the package. In this case, you have to open the Cask file by yourself.

Modify the Cask file

Now, we are going to specify the version of package by modifying the Cask file. All we have to do is to change the values of the version and the sha256. Take a look at the latest Cask file (still take Ansible as an example):

class Ansible < Formula
  include Language::Python::Virtualenv

  desc "Automate deployment, configuration, and upgrading"
  homepage "https://www.ansible.com/"
  url "https://releases.ansible.com/ansible/ansible-2.9.3.tar.gz"
  sha256 "2f83f8ccc50640aa41a24f6e7757ac062f83f8ccc50640aa41a24f6e7757ac06"
  revision 1
  head "https://github.com/ansible/ansible.git", :branch => "devel"

  bottle do
    cellar :any
    sha256 "2f83f8ccc50640aa41a24f6e7757ac062f83f8ccc50640aa41a24f6e7757ac06" => :catalina
    sha256 "97df95880897d23f6f56fb69d9772aa07f7693a6a61adcf2cc799b7733203081" => :mojave
    sha256 "1a645b578dd08bc43e62add53647f00e0ebd38a032057ca6065da08c3ec81c49" => :high_sierra
  end

Below is a modified example:

class Ansible < Formula
  include Language::Python::Virtualenv

  desc "Automate deployment, configuration, and upgrading"
  homepage "https://www.ansible.com/"
  url "https://releases.ansible.com/ansible/ansible-2.9.2.tar.gz"
  sha256 "2f83f8ccc50640aa41a24f6e7757ac06b0ee6189fdcaacab68851771d3b42f3a"
  revision 1
  head "https://github.com/ansible/ansible.git", :branch => "devel"

  bottle do
    cellar :any
    sha256 "2f83f8ccc50640aa41a24f6e7757ac06b0ee6189fdcaacab68851771d3b42f3a" => :catalina
    sha256 "97df95880897d23f6f56fb69d9772aa07f7693a6a61adcf2cc799b7733203081" => :mojave
    sha256 "1a645b578dd08bc43e62add53647f00e0ebd38a032057ca6065da08c3ec81c49" => :high_sierra
  end

Reinstall the package

Once modified the Cask file, let’s reinstall the package:

Reinstall a package

brew cask uninstall --force <PackageName>; brew cask install <PackageName>;

Reinstall the VirtualBox

brew cask uninstall --force virtualbox; brew cask install virtualbox;