Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Instructions to install an outdated Homebrew formula

Installing Old Homebrew Formulas

Over the past several years, Homebrew has made it continually difficult to install an outdated formula. I'm not quite sure why, but it's been a struggle for developers for the past 7+ years.

However, there is a workaround (however it's not straight-forward). For this example, I'll use ruby-build:

  1. Note the version you currently have installed:
$ ruby-build --version
ruby-build 20210825
  1. If the version you have installed is later than the one you want installed, try this:
$ brew install ruby-build@20210707
Warning: No available formula or cask with the name "ruby-build@20210707". Did you mean ruby-build?
==> Searching for similarly named formulae...
This similarly named formula was found:
ruby-build ✔
To install it, run:
  brew install ruby-build ✔
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.
  1. If that doesn't work (such as my example above), navigate to https://github.com/Homebrew/homebrew-core/find/master
  2. Search for the formula you'd like to install: image
  3. Click History to see the file's commit history: image
  4. Find the most recent commit that describes the formula version you want, and click the commit: image
  5. GitHub will highlight the file in that commit, and click the three dots on the upper right corner of the file, and then click View file: image
  6. Click Raw to view the entire file in its raw form: image
  7. On your terminal, create the file FORMULA.rb, and copy-paste the contents of the file from GitHub to the file on your machine:
$ touch ~/ruby-build.rb
$ vim ~/ruby-build.rb
# Copy-paste the contents from the GitHub file here
# Press :wq to quit when you're done
  1. Now install the formula from that file directly (you may need to unlink existing formula(s)):
$ brew install ~/ruby-build.rb
Error: Failed to load cask: /Users/emmasax/ruby-build.rb
Cask 'ruby-build' is unreadable: wrong constant name #<Class:0x00007fb7811c01c0>
Warning: Treating /Users/emmasax/ruby-build.rb as a formula.
Error: ruby-build 20210825 is already installed
To install 20210707, first run:
  brew unlink ruby-build

$ brew unlink ruby-build
Unlinking /usr/local/Cellar/ruby-build/20210825... 4 symlinks removed.

$ brew install ~/ruby-build.rb
Error: Failed to load cask: /Users/emmasax/ruby-build.rb
Cask 'ruby-build' is unreadable: wrong constant name #<Class:0x00007fd9a8bb7ba8>
Warning: Treating /Users/emmasax/ruby-build.rb as a formula.
==> Downloading https://ghcr.io/v2/homebrew/core/ruby-build/manifests/20210707
.
.
.
==> Summary
🍺  /usr/local/Cellar/ruby-build/20210707: 536 files, 266.5KB
Removing: /Users/emmasax/Library/Caches/Homebrew/ruby-build--20210707... (55KB)

$ ruby-build --version
ruby-build 20210707

Voilá! And, we can see all versions of the formula on our machine:

$ ls /usr/local/Cellar/ruby-build/
20210707        20210825

Unfortunately, doing any sort of brew upgrade or brew unlink FORMULA && brew link FORMULA will get you back to where you started. You can try to implement something like this, but I haven't tested any of that personally.

Best of luck brewing!

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