0

I want to compile my Go code in windows 10 for Linux (Ubuntu).

I use the commands:

SET GOOS=linux
SET GOARCH=amd64
go build .\main.go

but the compiler creates an .exe file.

How to cross-compile this code for linux?

georgeok
  • 5,321
  • 2
  • 39
  • 61
mohammad ghari
  • 153
  • 2
  • 13

2 Answers2

7

If you use PowerShell then you should use $Env:GOOS = "linux"; $Env:GOARCH = "amd64"; go build .\main.go

Vitaly Migunov
  • 4,297
  • 2
  • 19
  • 23
0

Try this like a one line command in the terminal: GOOS=linux GOARCH=amd64 go build .\main.go

  • 1
    I did it but made a mistake,GOOS=linux : The term 'GOOS=linux' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + GOOS=linux GOARCH=amd64 go build .\main.go + ~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (GOOS=linux:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException – mohammad ghari Jun 09 '19 at 11:29