HiveBrain v1.2.0
Get Started
← Back to all entries
snippetdockerMinor

How to create Golang Linux binaries using a Windows host

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
binariescreatehostusinglinuxhowwindowsgolang

Problem

When go build is issued on a Windows host a .exe binary is created. How to ensure that a Linux binary is created on a Windows host?

The following was tried, but did not solve the issue:

GOOS=linux;go build hello-world.go

Solution

You can easily set the target operating system and processor architecture using the environment variables GOOS and GOARCH respectively. So, as you want to build it for linux operating system, following command with above environment variables will do,

$ GOOS=linux GOARCH=amd64 go build -o hello main.go


Here is the list of all the supported operating system with which you can easily do cross compilation using Go lang.

Code Snippets

$ GOOS=linux GOARCH=amd64 go build -o hello main.go

Context

StackExchange DevOps Q#1671, answer score: 4

Revisions (0)

No revisions yet.