Compiling a Go package without Go installed through code

Hello,
I’ve got a bit of a weird question here. It probably doesn’t make sense at all, but I figured I would just ask anyway, to see if there’s any alternative way to get around this.

To explain my situation: I have a compiled Go program. With this Go program, I would like to compile other Go programs. I would use exec.Command to simply go build the other programs, but I’m sure that does not work if Go is not installed on the system the program is being ran on, and ideally I’d like to be able to distribute the compiled Go program without people needing to install Go in order to run it.

Is there any other way to compile a Go package from compiled Go code, without having Go installed on the system the program is ran on?

Thanks in advance,

There is no way to compile go code without Go installed in the traditional sense. Alternatives would include having pre-compiled binaries in the target architecture.

1 Like

You may compile your golang code from a docker container without having go binaries installed on your machine.

docker run --rm -v “$PWD”:/usr/src/myapp -w /usr/src/myapp -e GOOS=linux -e GOARCH=amd64 golang:1.8 go build -v

https://hub.docker.com/_/golang/

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.