Build Environment Variables in Go

13 May 2022

I want to customize the build process of a piece of go code. It’s dockerized. I know there are a few parameters I want to use, like -modfile that lets you change the go.mod and go.sum files used to build the app.

When you build a piece of code with go, the compiler looks into some env variables like GOARCH and GOPATH to configure the build. If you want to pass an additional option, use GOFLAGS=....

List Of Go Build Flags

Complete list:

https://pkg.go.dev/cmd/go#hdr-Environment_variables

Some:

  • GOROOT
  • GOBIN
  • GOOS
  • GOARCH
  • GOPATH
  • GO111MODULE
  • GOCACHE
  • GOVCS
  • GCCGO
  • GIT_ALLOW_PROTOCOL
  • GOPRIVATE
  • GOPROXY

Laurent Senta

I wrote software for large distributed systems, web applications, and even robots. These days I focus on making developers, creators, and humans more productive through IPDX.co.