Cross Compile Your Go Programs

Ardan Labs Blog on ·

Introduction

In my post about building and running programs in Iron.Io (https://www.ardanlabs.com/blog/2013/09/running-go-programs-in-ironworker.html), I needed to switched over to my Ubuntu VM to build linux versions of my test programs locally. I love the ability to have Ubuntu available to me for building and testing my code. However, if I can stay on the Mac side it is better.

I have wanted to learn how to cross compile my Go programs for the two platforms I use, darwin/amd64 and linux/amd64. This way I could create final builds of my programs and publish everything from my Mac OS. After a couple of hours I am finally able to do this.

If you don’t have the need to cross compile your code then I recommend you stick with the traditional distribution packages and installs for Go. If this is something you need, then it all starts with downloading the current release of the Go source code.

Installing Git

The Go source code is stored in a DVCS called Github and is located on github.com/golang/go (http://github.com/golang/go). The first thing you need to do is install Git if you don’t already have it.

Go to the download page on the Git website:  http://git-scm.com/downloads (http://git-scm.com/downloads)