How to downgrade hugo to a previous version?

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:

  1. Uninstall the current version with brew uninstall hugo
  2. Visit https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/hugo.rb
  3. Click the “History” link
  4. Find the “bottle” commit for the desired version (example: hugo: update 0.99.1 bottle)
  5. Press the “View at this point in history” button
  6. Press the “Raw” button
  7. Right-click anywhere on the page and choose “Save as…”
  8. Save hugo.rb to any directory (home, downloads, etc.)
  9. Open a terminal
  10. CD into the directory where you saved the hugo.rb file
  11. Install with brew install hugo.rb
  12. 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.

8 Likes