If you build the go program on a Linux machine, it should just work elsewhere, if you mark it as executable chmod +x /path/to/main.go
.
You can specify the build using env
and the go build
cmd tool which architecture to build for (or which OS), for example:
env GOARCH=arm go build main.go
If you want, you can specify Linux with
env GOOS=linux go build main.go
Note, these are the target environments:
Note that $GOARCH and $GOOS identify the target environment, not the environment you are running on. In effect, you are always cross-compiling. By architecture, we mean the kind of binaries that the target environment can run: an x86-64 system running a 32-bit-only operating system must set GOARCH to 386, not amd64.
see here for a full list of distros and architectures:
https://golang.org/doc/install/source#environment