Installing Go on Apple Silicon
Presently you're unable to install Go via Homebrew on the new M1 Mac systems. While it's expected to be working in the beginning of 2021 I personally couldn't wait that long as there's some tools I use on a daily basis that require Go. Thankfully there's a method you can follow to get Go installed on your M1 Mac for the time being.
First ensure that you have git installed and that you have a copy of the current go package. For the go package I downloaded this file to my Downloads directory. It basically acts as a bootstrap environment so we can build our own version of Go that is native to ARM64. Make sure you uncompress it. It should result in a new directory named 'go'.
Next we need to get a copy of the current Go source. We can do this by running:
mkdir ~/Developer && cd ~/Developer git clone https://go.googlesource.com/go
Then navigate into the clone repository and checkout the master branch:
cd ~/Developer cd go.googlesource.com/go git checkout master
Next we need to compile a version of Go which will work on our M1 system. In the following command you'll want to adjust
$USERNAME so it's your username.
arch --x86_64 env GOROOT_BOOTSTRAP=/Users/$USERNAME/Downloads/go GODEBUG=asyncpreemptoff=1 GOOS=darwin GOARCH=arm64 ./bootstrap.bash
I've moved the built binaries into my Homebrew installation but this isn't required. Don't forget to update
$USERNAME to your username.
cd /opt/homebrew/Cellar && mkdir go && cd go && mkdir 1.15.6 && cd 1.15.6 && mkdir bin && mkdir libexec cd bin && cp -v /Users/$USERNAME/Developer/go.googlesource.com/go-darwin-arm64-bootstrap/bin/* cd ../libexec && cp -Rv /Users/$USERNAME/Developer/go.googlesource.com/go-darwin-arm64-bootstrap/* . cd /opt/homebrew/bin ln -s ../Cellar/go/1.15.6/bin/gofmt . ln -s ../Cellar/go/1.15.6/bin/go .
I have this set in my
.zshrc so it allows the binaries to work from Homebrew:
If everything worked, the following command should return the Go version (your output may be a bit different, specifically the commit version):
$ go version go version devel +e508c1c67b Fri Dec 11 08:18:17 2020 +0000 darwin/arm64
This article was put together using my
.zsh_history and memory so there's a chance something may not work 100%. If that's the case please don't hesitate to leave a comment and let me know. I probably should have written this right after I did this myself, oops!