Update from 2020: the instructions for tesseract don’t work anymore, see comments from other users below the post.
I’ll use Tesseract as an example, but the same logic can be applied to any other Homebrew package.
Backstory: I ran
brew upgrade which upgraded Tesseract on my computer from version 3.05 to version 4.0.0. The new version didn’t work the way I wanted, so I decided to downgrade it. It turned out pretty easy.
Once again: in the commands listed below replace tesseract with the name of the package that you want to downgrade.
Step 1. Run
brew info tesseract and find the formula link. Example: https://github.com/Homebrew/homebrew-core/blob/master/Formula/tesseract.rb
Step 2. Open the formula link in your web browser, click “Raw” and note the URL. Example: https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/tesseract.rb
Step 3. Run
brew log tesseract. Since homebrew uses git version control system, all changes to its formulae are stored in ‘commits’. You need to choose the id (aka hash) of the commit that you want to downgrade to. The newest commits will be at the top. I picked a commit with the id
Step 4. Replace
master in the URL from Step 2 with the commit id from Step 3. Example: https://raw.githubusercontent.com/Homebrew/homebrew-core/5df6eb919506a097b2efb1df34a16e3a147c8731/Formula/tesseract.rb
Step 5. Uninstall the newer version of the package from your system:
brew uninstall tesseract
Step 6. Install the older version of the package using the URL from Step 4. Example:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/5df6eb919506a097b2efb1df34a16e3a147c8731/Formula/tesseract.rb
Step 7. ‘Pin’ it:
brew pin tesseract — ‘pinning’ tells Homebrew to keep the older version when you do brew upgrade.