Now that you have your program ready after testing it with go run, you want to build it as a single program for future use. This guide will show you how to do a simple Go Build.
First you need to know where is your output location. Otherwise, Go Build will save it in your current directory. Example, if I want to save it to my current directory bin folder, I recognize the output path as:
./binWith that, you're ready. Go ahead and perform the build using the following command:
$ go build ./cmd/YourApp/main.goor if you want to specify an output path
$ go build -o ./bin/myProgram ./cmd/YourApp/main.goOnce done, try to run that program. You should be able to use like just like go run. On Linux, the command is something like:
$ ./path/to/bin/myProgramHello World!$That's all about the simple Go Build method. Remember, it can only simply compile to your existing CPU and operating system.