TLDR: Use something other than Homebrew
Only a few of the Homebrew packages have version-specific formulae. See this list. Go, for example, has version-specific formulae, but Git does not.
If someone had the time and inclination, they could submit version-specific formulae for Hugo, but those formulae are subject to these restrictions. Most notably:
Versioned formulae should differ in major/minor (not patch) versions from the current stable release
That means that we could have formulae for v0.101.0 and v0.102.0, but not for v0.102.1, v0.102.2, or v0.102.3.
I agree.
The current version of Homebrew is v3.6.0. The switch
command was removed in v2.6.0. Prior to v2.6.0, provided you had not run brew cleanup
, you could easily revert to an earlier installation with something like:
brew switch hugo 0.102.1
But you can’t do that anymore.
I spent far too much time researching methods to install a specific version via Homebrew when the package does not have version-specific formulae. This looked promising, but threw an error.
This is the best method that I can find so far:
- Uninstall the current version with
brew uninstall hugo
- Visit https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/hugo.rb
- Click the “History” link
- Find the “bottle” commit for the desired version (example: hugo:
update 0.99.1 bottle
) - Press the “View at this point in history” button
- Press the “Raw” button
- Right-click anywhere on the page and choose “Save as…”
- Save
hugo.rb
to any directory (home, downloads, etc.) - Open a terminal
- CD into the directory where you saved the
hugo.rb
file - Install with
brew install hugo.rb
- Prevent automatic updates with
brew pin hugo
Compare that with building from source:
# Install the latest version
go install -tags extended github.com/gohugoio/hugo@latest
# Downgrade to something else
go install -tags extended github.com/gohugoio/hugo@v0.100.1
The first time you build from source, it will take a minute or two as Go primes the module cache. Subsequent builds will generally be much faster.