Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
kubectl multi-version brews (kubernetes-cli formula)

kubectl multi-version brews

We need to run multiple versions of kubectl for compatibility with various kubernetes clusters.

It's a bit easier to get and use multiple versions of kubectl using Homebrew than it is using Macports.

With brew, it's simple to:

  • Install a bunch of versions of kubectl (in the kubernetes-cli Formula)
  • Switch between them as needed
  • Pin a particular release so you don't auto-upgrade into incompatibility with your kubernetes cluster(s)


Get the versions and commit IDs from

or locally from your homebrew-core clone

     cd ~/src/

     git log master -- Formula/kubernetes-cli.rb

Then use the commit IDs to fetch a specific version via

    brew install{commitIDhere}/Formula/kubernetes-cli.rb

(See Example Install Commands below)

Initial Installs

If you install a bunch of versions and set environment variable HOMEBREW_NO_INSTALL_CLEANUP, they'll be available for hot brew switch action later.

To keep prior versions around despite brew's new default behavior of automatically running cleanup (nuke) during installs of newer versions, run


or maybe even put it in your .profile || .bashrc if you have the disk for old versions in general.

Between each initial version install, you'll need to unlink each time to make way for the next version

     brew install ...

     brew unlink kubernetes-cli

     brew install ...

     brew unlink kubernetes-cli


Once you have the versions installed, you don't need to unlink to switch between the versions.


To link up a specific version from your available versions

  • Check your active version

     kubectl version

  • Get available versions, short form, using the bogus version trick

     brew switch kubernetes-cli 0

  • Pick one version

     brew switch kubernetes-cli 1.8.5

  • Or pick another version

     brew switch kubernetes-cli 1.11.3

You could also get versions, long form with other info

     brew info kubernetes-cli


Once you're switched to a version you want to stick with for a while, you can pin it to prevent upgrades during a global brew upgrade.

     brew pin kubernetes-cli

You'll need to brew unpin kubernetes-cli when you want to move back to the head release. Otherwise, you can switch between previously installed Formula versions while pinned.

Example Install Commands

Here are some versions' commit IDs all set up for you.


brew install


brew install


brew install


brew install


brew install


brew install


brew install


brew install


brew install


brew install


brew install


brew install


brew install


brew install


This comment has been minimized.

Copy link

onmomo commented Oct 21, 2019

thanks for this!


This comment has been minimized.

Copy link

mathiasPop commented Oct 30, 2019

Great! Thanks for this! Will you keep it up to date?


This comment has been minimized.

Copy link
Owner Author

rdump commented Nov 10, 2019

Yes, updated occasionally to get the latest x.x.Y version in the list. And with instructions to avoid nuking old versions by default, or the like.


This comment has been minimized.

Copy link

michaeljohnbennett commented Feb 27, 2020

dude, why is this not in the JX doc package! This is so important, so much problems installing the correct kube and helm versions on OSX today trying this out.


This comment has been minimized.

Copy link

naviat commented May 9, 2020

Thanks @rdump !


This comment has been minimized.

Copy link

yosit commented May 9, 2020

asdf has an excellent support for kubectl:
asdf plugin add kubectl
asdf install kubectl 1.15.10
asdf install kubectl latest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.