Reputation: 550
I have a Go file and I would like to give it to the customers. The customers should be able to execute using a command in terminal. They will not install Go lang in their system.
How to do run this binary file in clients machine? Please help me.
Upvotes: 0
Views: 487
Reputation: 417542
Go is a compiled language. You can use the Go tools to compile your Go app to an executable binary. Once you have the executable binary, you can run it as-is, the Go installation is not needed / used anymore. Since Go is statically linked, all the dependencies will be compiled / linked into the executable.
More specifically:
go install
to compile your app and "install" the executable binary to your $GOPATH/bin
foldergo build
to compile your app and get the executable binary in the current working directoryRead What does go build build? for more details.
All you need is to pass on the executable binary to your customer. If your app uses static files, of course you have to pass them too, preferably packed into one compressed file.
Note that an executable binary targets a specific platform. You have to consult your customer about what platform he intends to run your app on, and compile your app to that specific platform.
The target OS and platform can be set using the GOOS
and GOARCH
environment variables. For example, if your customer wants to run your app on Windows amd64, you can produce a Windows amd64 executable like this:
GOOS=windows GOARCH=amd64 go build
For a list of valid GOOS
and GOARCH
values, see How can I build for linux 32-bit with go1.6.2.
Upvotes: 4