Skip to main content

Command Palette

Search for a command to run...

Compiling go for Apple Silicon

Published
3 min read

Compiling go for Apple Silicon devices is fairly straight forward. To get a working binary we'll need an x86 device to use for cross-compilation. In this case we're going to use a DigitalOcean droplet.

Note! Currently only the unreleased go 1.16 supports Apple Silicon, so we're going to be compiling from the master branch

We're going to start by creating a new DigitalOcean droplet with Ubuntu 20.04. It's only going to be running for 10 - 15 minutes, so we'll give it a fair bit of processing power to compile go more quickly.

image.png

Once your droplet has finished creating, grab the public IP address and SSH into it as the root user.

ssh root@IP_ADDRESS

To build go from source we need a bootstrap version of go. We can install a copy from Ubuntu's apt repository using the following command.

apt-get install golang -yy

Now that you've got a bootstrap compiler we're going to clone down go's GitHub repository and cross-compile it.

git clone https://github.com/golang/go.git
cd go/src
GOARCH=arm64 GOOS=darwin ./bootstrap.bash

Now that we've built our binary we're going to return to our Apple Silicon Mac and copy down the built archive.

scp root@IP_ADDRESS:~/go-darwin-arm64-bootstrap.tbz .

Extract this archive using Archive Utility and now it's time to add the bin directory to your path.

ZSH

Add the following line to your ~/.zshrc

export PATH=~/go-darwin-arm64-bootstrap/bin:$PATH

Source your new config

source ~/.zshrc

Fish Shell

Add the following line to your fish config in ~/.config/fish/config.fish

set -gx PATH ~/go-darwin-arm64-bootstrap/bin $PATH

Source your new config

source ~/.config/fish/config.fish

Summary

You should now have a working go compiler on your path that can create native Apple Silicon binaries! 🎉