How to build a release version binary in Go?

Solution 1:

In Go, it isn't typical to have a debug version or a release version.

By default, go build combines symbol and debug info with binary files. However, you can remove the symbol and debug info with go build -ldflags "-s -w".

Solution 2:

You can instruct the linker to strip debug symbols by using

go install -ldflags '-s'

I just tried it on a fairly large executable (one of the GXUI samples), and this reduced it from ~16M to ~10M. As always, your mileage may vary...

Here is a full list of all linker options.