Nitin's Blog

Nitin's Blog

Upgrade or Downgrade Go installed with Homebrew.

Upgrade or Downgrade Go installed with Homebrew.

How to upgrade or downgrade Go installed with Homebrew.

While working in cross team environment, I just had the issue that I installed Go 1.14 which messed up my VSCode auto completion and it is also not supported by the CI/CD pipeline I was using. This meant I needed to downgrade to lower Go versions either 1.12/1.13.

This took me a more longer than I’d be willing to expected a fix. Partially because the naming in Homebrew is sometimes a bit hard to follow #11091 .

Here are 3 simple steps involved:

  • Install wanted version,
  • unlink old one,
  • link new one.

Check current version

 ~ go version                                                                                                                                                                                            
go version go1.14.13 darwin/amd64

Install specific go version you want

The available versions are listed in the Hombrew directory. The Example for Go would be here .

~ brew install go@1.12
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> Updated Formulae
openssl@1.1 ✔
==> Downloading
Already downloaded: /Users/username/Library/Caches/Homebrew/downloads/6392e5d3faa67a6132d43699cf470ecc764ba42f38cce8cdccb785c587b8bda8--go@1.12-1.12.9.mojave.bottle.tar.gz
==> Pouring go@1.12-1.12.9.mojave.bottle.tar.gz
==> Caveats
go@1.12 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have go@1.12 first in your PATH run:
  echo 'export PATH="/usr/local/opt/go@1.12/bin:$PATH"' >> ~/.zshrc

==> Summary
🍺  /usr/local/Cellar/go@1.12/1.12.9: 9,819 files, 452.8MB
~ brew unlink go
Unlinking /usr/local/Cellar/go/1.14... 3 symlinks removed

As the specific formula we want (go@1.12) is a keg-only formula it must be linked with --force. If you try without it’ll tell you just that. As explained in the FAQ a key-only formula is one that’s only installed into our /usr/local/Cellar directory without being linked automatically.

~ brew link --force go@1.12
Linking /usr/local/Cellar/go@1.12/1.12.9... 3 symlinks created

If you need to have this software first in your PATH instead consider running: echo 'export PATH="/usr/local/opt/go@1.12/bin:$PATH"' >> ~/.zshrc

Check version

Now that everything is linked correctly it should show the specific version we want:

~ go version
go version go1.12.9 darwin/amd64
Share this