Build

A binary can also be built in a specific location using the go build command. A specific output file can be defined using the -o flag, otherwise it will be built in the working directory, using the package name as a binary name:

# building the current package in the working directory
$ go build .

# building the current package in a specific location
$ go build . -o "/usr/bin/mybinary"

When executing the go build command, the argument can be one of the following:

The latter case allows you to build a file that is outside $GOPATH and will ignore any other source file in the same directory.