How to compile Go program binary to run on your Linux box or Linode Server

TL;DR Follow these simple steps to compile a binary for running on Linode VPS machines.

How to compile Go program binary for running on your Linode Server

I use Linode VPS for running my experiments and hosting websites. My primary development machine is Windows 10 and very frequently I need to cross-compile go program binaries to Linux OS that is the primary OS on Linode servers. Instead of doing a google search each time I need to do the cross-compilation, I thought to document the steps here so that I can refer it whenever I need.

Here are the steps that needs to be executed on the Windows Command Prompt:

set GOARCH=amd64    #Target Processor architecture [amd64, 386, arm]
set GOOS=linux      #Target Operating System where program will run [linux, darwin, windows] 
go build -v         #Start build in verbose mode
Flag -v is verbose mode and compiler prints the names of the packages as they are compiled

You can lookup other flags like -a, etc. on golang.org website.

We can do better. We can make use of Windows batch script so that we won’t have to type those individual commands each time on the console.