Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build a go binary for both Linux and Mac [duplicate]

Tags:

go

How can I go build a project in a way that it works for both Mac and Linux (x86 and x64)? Is that even possible?

I searched and found some stuff, but cannot make them work (or maybe I just didn't understood them).

like image 752
caarlos0 Avatar asked Mar 17 '26 03:03

caarlos0


1 Answers

To build binaries for different platforms, I use GOX

Gox is a simple, no-frills tool for Go cross compilation that behaves a lot like standard go build. Gox will parallelize builds for multiple platforms. Gox will also build the cross-compilation toolchain for you.

You tell it which platforms you want to target, and one command will build a separate binary for each of them. One binary cannot target multiple systems though.

To build for OSX (64 bit) and Linux (32 and 64 bit), you could use:

gox -osarch="darwin/amd64 linux/386 linux/amd64"
like image 95
Colin Nicholson Avatar answered Mar 18 '26 17:03

Colin Nicholson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!