Skip to content

Compile

We've actually already covered the process of compiling the application, but let's go over it again briefly.

Note

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:

1
go build -v -o "httpcats"

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.)

1
GOOS=linux GOARCH=amd64 go build -v -o "httpcats"

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
  • GOARCH

The 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:

1
httpcats: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, Go BuildID=XeKrZ8z0M7f_OMvZN0ej/DhDOOsvonFScJFkQj5oD/tcUCDkIdENsqaqF1GDRk/JpzMCA_sppmg8EEadHPe, not stripped

The important parts of this line are ELF 64-bit and x86-64. That's what we're looking for.

Next Steps

Now we need to package up our application and associated files so we can deploy it.


Last update: August 29, 2021