Setting up to Go #
Install #
Install Go lang from go.dev.
go version
To update, download and install the new version.
To uninstall, rm -rf /usr/local/go
.
Hello, world! #
Create a hello.go
file.
package main
import "fmt"
func main() {
fmt.Printf("Hello, world!\n")
}
go run hello.go
Build a native binary in release mode.
go build -tags release hello.go
To cross compile
# List all available targets (GOOS/GOARCH pairs)
go tool dist list
# Build a binary for Windows on 64 bit x86
GOOS=windows GOARCH=amd64 go build -tags release hello.go
# For Linux on 64 bit x86
GOOS=linux GOARCH=amd64 go build -tags release hello.go
# For Linux on ARM 64 bit
GOOS=linux GOARCH=arm64 go build -tags release hello.go