✅ 常见平台示例
- 编译为 Linux(64位)
GOOS=linux GOARCH=amd64 go build -o app-linux-amd64
- 编译为 Windows(64位,.exe 文件)
GOOS=windows GOARCH=amd64 go build -o app-windows-amd64.exe
- 编译为 macOS(64位 Intel)
GOOS=darwin GOARCH=amd64 go build -o app-darwin-amd64
- 编译为 macOS(M1/M2 ARM)
GOOS=darwin GOARCH=arm64 go build -o app-darwin-arm64
- 编译为 Linux ARM(如树莓派)
GOOS=linux GOARCH=arm GOARM=7 go build -o app-linux-armv7
- 编译为freebsd
GOOS=freebsd GOARCH=amd64 go build -o app-freebsd main.go
文档信息
- 本文作者:JiliangLee
- 本文链接:https://leejiliang.cn/2025/08/06/all-golang-build-command/
- 版权声明:自由转载-非商用-非衍生-保持署名(创意共享3.0许可证)