We've actually already covered the process of compiling the application, but let's go over it again briefly.
Just a reminder that you're going to need to install Golang before you can proceed.
The easiest way for us to compile our application is as possible:
This will give us a binary for our local architecture called
httpcats. However we need a binary suitable for running on Linux (because our EC2 instances are using Ubuntu Linux.)
So what have we changed here? We've added to two temporary environment variables (they only apply to this one command; they don't persist):
GOOS variable is indicating to the Go compiler that we want to compile for
linux (in our case.) The
GOARCH variable is telling the Go compile we want to compile our binary for the x86 64-bit instruction set/architecture, which is the most common architecture you're likely to use.
If we use the
file utility on Linux and study the binary we get, we can see it is indeed suitable for executing on Linux:
The important parts of this line are
ELF 64-bit and
x86-64. That's what we're looking for.
Now we need to package up our application and associated files so we can deploy it.