I want to compile a Go programm for a linux machine. I always used that way which is described here:
How to cross compile from Windows to Linux?
That worked pretty well until the last big update from Windows 10. Now I am not able to set the GOOS
with
set GOOS=linux
I also tried to start the PowerShell as administrator, but even that is not working. Are there any tools which can do that? Or is there another way to crosscompile Go program on Windows 10?
set
is an internal command of the Windows command line interpreter (cmd.exe
).
If you're using PowerShell, then changing values of environment variables should be done like:
$Env:<variable-name> = "<new-value>"
For more details, see PowerShell documentation: About Environment Variables
So to change GOOS
, use:
$Env:GOOS = "linux"
To do a cross-compilation:
Navigate to the folder where the main
package is.
Run $Env:GOOS = "linux"
Optionally run $Env:GOARCH = "amd64"
Run go build
Or you can do it in a single line:
$Env:GOOS = "linux"; $Env:GOARCH = "amd64"; go build
To specify the output file name:
$Env:GOOS = "linux"; $Env:GOARCH = "amd64"; go build -o hello