Skip to content

Instantly share code, notes, and snippets.

@rbanick
Last active August 25, 2020 23:21
Show Gist options
  • Save rbanick/b143ca6bb4670c1d99f6 to your computer and use it in GitHub Desktop.
Save rbanick/b143ca6bb4670c1d99f6 to your computer and use it in GitHub Desktop.
How to manually roll back homebrew formula on a UNIX platform

Rolling back Homebrew formula on a UNIX platform

The problem

Sometimes brew updates break your computer or a piece of software. This is usually really unpleasant as it can take some time to diagnose which formula at which version did so. Even if you can diagnose, it's not very clear how to roll back homebrew softwares to previous versions.

How to fix it

The process is as such:

  1. Brew uninstall the software in question
  2. Replace the brew formula for that software with an older version
  3. Brew install your software. Brew will read your formula and install the older, non-toxic software.

Replacing the brew formula

This is the hardest part. Brew isn't very transparent about where and how these formula are stored.

  1. Each formula is stored as a .rb file
  2. From a friend's computer or homebrew/versions (https://github.com/Homebrew/homebrew-versions) get the old .rb file for your software (e.g. qt.rb)
  3. Go to /usr/local/Library/Formula
  4. Copy out the existing .rb file for your software just in case. Store it somewhere safe
  5. Now overwrite the .rb file in your Formula folder with the older .rb file.
  6. Done!

Alternate method

If you really want to, you can edit the .rb file instead of replacing it.

In that case, you should replace the key items under stable do and bottle do. These are located at the top of the .rb file. New urls should be provided for url and mirror and you will need to find the unique homebrew update text string that goes under sha256. If you have an older version of OS X installed you will also need to find the string that's appropriate for that version.

Note: finding these strings is not fun. I haven't found a reliable source (comment on this gist if you know of one).

Example

  stable do
    url "https://download.qt.io/official_releases/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.tar.gz"
    mirror "https://www.mirrorservice.org/sites/download.qt-project.org/official_releases/qt/4.8/4.8.7/qt-everywhere-opensource-src-4.8.7.tar.gz"
    sha256 "e2882295097e47fe089f8ac741a95fef47e0a73a3f3cdf21b56990638f626ea0"
  end

  bottle do
    sha256 "540e72bee0f660e0aeebe84ce04408fd45642fd987e304c9591b2648af55672b" => :yosemite
    sha256 "27e20d9f5b17df87e49ae9d6fe15105ac83a79b2a364884cdfd17e55e02d6ea1" => :mavericks
    sha256 "c03ff74ad662f1aafb048f6d016f76bf510da328752453ae4b7e6aaa6402e9b9" => :mountain_lion
  end

Final notes

Homebrew versions is a (very) partial record of previous homebrews. They only seem to stash major formula there (e.g. postgres) and it doesn't seem to be taken seriously as a repository for formula rollbacks. A friend's computer is likely a more viable option for the .rb files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment