How to Generating exe from Linux OS and the opposite?

hi , i am using linux , after writing a go script you type
go build filename.go
then the executable is generated …

now this executable will work only on linux , so i want to take this executable and make it work on windows , how can i do that ? or how can i generate .exe file on linux ? and the opposite also , if i am using windows , how can i generate linux executable ?

thank you for your support

As long as you use pure go code without any FFI or syscalls, just using the GOOS and GOARCH environment variables should suffice.

Please refer to for a list of possible combinations. This list might neither be exhaustive, nor up to date.


Just install Go on WIndows, copy the source(s) and compile on Windows. I’ve done that more than once

1 Like

It’s easier than you think:

GOOS=windows GOARCH=amd64 go build filename.go

See my presentation about Go:

Page 27.

Good luck!

Jeff Kayser

1 Like

no need to do this , as mr jeff wrote , you can easily do it on linux
GOOS=windows GOARCH=amd64 go build filename.go

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.