Skip to content

Instantly share code, notes, and snippets.

@philippetedajo
Created February 1, 2023 16:03
Show Gist options
  • Save philippetedajo/50cd6009a3fd3ba6c3599e828d18582e to your computer and use it in GitHub Desktop.
Save philippetedajo/50cd6009a3fd3ba6c3599e828d18582e to your computer and use it in GitHub Desktop.
Homebrew: Install an older version of a formula

Homebrew: Install an older version of a formula

kubernetes-cli (v1.10.3) taken as example

  1. Downgrade Homebrew to the commit which upgrades the formula to the specific version that we want
$ cd "$(brew --repo homebrew/core)"
$ git log Formula/kubernetes-cli.rb

...
commit 0c1a8d9cab85af1a1e519071b40fd254a8a27265
Author: BrewTestBot <[email protected]>
Date:   Wed Jun 6 00:54:22 2018 +0000

    kubernetes-cli: update 1.10.3 bottle.

commit 8f44eaa38a71df4a25823f79d9da96fa58fc51fa
Author: Ronny Haryanto <[email protected]>
Date:   Wed Jun 6 09:48:45 2018 +1000

    kubernetes-cli 1.10.3

    Closes #28693.

    Signed-off-by: ilovezfs <[email protected]>
...

$ git checkout -b kubernetes-cli-1.10.3 0c1a8d9cab85af1a1e519071b40fd254a8a27265
  1. Unlink, in case we already have a version installed
$ brew unlink kubernetes-cli
  1. Install and force Homebrew not to update itself and the list of formulae
$ HOMEBREW_NO_AUTO_UPDATE=1 brew install kubernetes-cli
  1. Pin the formula to prevent Homebrew from updating it
$ brew pin kubernetes-cli
  1. After installation, the version specified is automatically linked
$ brew info kubernetes-cli
kubernetes-cli: stable 1.11.0 (bottled), HEAD [pinned at 1.10.3]
Kubernetes command-line interface
https://kubernetes.io/
/usr/local/Cellar/kubernetes-cli/1.10.3 (178 files, 52.8MB) *
  Poured from bottle on 2018-07-11 at 16:22:16
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/kubernetes-cli.rb
==> Dependencies
Build: go ✔
==> Options
--HEAD
	Install HEAD version
==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
  1. Cleanup
$ git checkout master
$ git branch -d kubernetes-cli-1.10.3
$ brew cleanup && brew prune

Credits: Zoltan Altfatter

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