Photo by Chinmay Bhattar / Unsplash

Homebrew App Switching

Oct 3, 2022

Author: Brandon B. Jozsa

"It is the sweet simple things in life which are the real ones afterall."
- Laura Ingalls Wilder

So I like a lot of things about the M1 MacBook that work's provided, but one of the interesting things that I've been running into is reducing the amount of applications that are being addressed by Rosetta 2. First, let me just say upfront that Rosetta 2 is pretty much bonkers (in a good way). So many things just run. It's pretty amazing. But this also leads to a false sense of comfort - thinking that things just work, when under the hood there's a lot more going on.

So because of this, I've recently rebuilt my laptop and refused to copy from a previous backup/install in order to reduce the amount of x86_64-based applications from carrying over to the new environment. When I restored my laptop previously, I failed to consider there were a lot of applications that would be carried over, and running like normal comes with a compute tax (not kidding - I was getting a lot of crashes). Now, things run GREAT!

But this also means that I need to rebuild the binaries that I previously used, like:

...and of course...that brings me to other interesting issues (although not uncommon at all)...

Switching Homebrew Application Versions

So we're sort of at this point where some projects are still using various versions of Golang, and you could have to use anything from 1.17-1.19 (time of writing is 03-OCT-2022). How do you cleanly switch between them?

Homebrew used to have this nice little subcommand called switch which would basically switch between one version or another. It used to work like this:

brew install go@1.16.10
brew switch go 1.16.10 

Now that this switch option has been removed, you can use the following instructions.

  1. First check which versions of go are installed via homebrew in the following directory (remember, this is specifically for an M1 macOS environment).
❯ ls /opt/homebrew/opt/ | grep 'go@'
go@1.17 

2. If there's another version of golang that you want to use, install that now.

brew install go@1.18

2. Check the install (just to be sure)

❯ ls /opt/homebrew/opt/ | grep 'go@'
go@1.17
go@1.18 

3. Now for the difference from brew switch. Do the following if you don't have any other versions of golang.

brew unlink go 

4. If you have multiple versions of golang already, than call this out specifically.

brew unlink go@1.17 

5. Install the new version of golang.

brew install go@1.18 

6. Finally, link and overwrite the new version you want to use.

brew link go@1.18 --overwrite
export PATH="/opt/homebrew/opt/go@1.17/bin:$PATH" 

It's important to export your PATH, and be sure to put this into your ~/.bashrc or ~/.zshrc file.

7, When you want to switch back now, all you have to do is the reverse for the older version, like this.

brew link go@1.17 --overwrite
export PATH="/opt/homebrew/opt/go@1.17/bin:$PATH" 

That's it! This was a really simple one today folks, and most of you already know this stuff. It's just helpful to have something that newer folks can easily reference when they need it!