golang cannot execute binary file: Exec format error

Viewed 62676

my go env

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH=""
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT=""
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

I compiled and successfully executed the binary on my mac and then copied it to the ubuntu machine whose go env is show above. When I call myprog binary, I get

bash: /usr/local/go/bin/myprog: cannot execute binary file: Exec format error
4 Answers

I had the same problem. I installed 64-bit version of go instead of 32-bit version. After installation of 32-bit version it works fine.

On windows, make sure you(or your IDE) is not running PowerShell - powershell will not take the set GOOS and not throw an error and will still compile the binary and you'll find this error when you deploy the binary to the server.

This happened to me when I was downloading the x86 version of golang, but the VM i provisioned was an ARM cpu.

You can get ARM downloads here: https://go.dev/dl/

Related