The problem

When installing Golang 1.14 using Homebrew, a request timeout error is reported when executing go Build

The brew install go@1.14... = = > go build Last 15 lines from/Users/xx/Library/Logs/Homebrew/go@1.14/03. Go: the 2021-08-18 01:14:01 + 0800 go build go: golang.org/x/net@v0.0.0-20190620200207-3b0461eec859: Get "https://proxy.golang.org/golang.org/x/net/@v/v0.0.0-20190620200207-3b0461eec859.mod" : dial TCP 142.251.43.17:443: i/o timeoutCopy the code

Problem orientation

It was preliminarily determined that there was an agent problem during the ‘Go Build’ execution. Domestic users need to set the proxy

Configuration goproxy

Try setting the above environment variables

export GOPROXY=https://goproxy.io,direct
export GO111MODULE=on
Copy the code

Unfortunately, the same error is reported, suspecting that an environment variable was unset somewhere during the installation process

View more installation information

Use the -v parameter for installation

The brew install go@1.14 - vCopy the code

See the homebrew install golang 1.14 ruby script path: ‘/ usr/local/homebrew/Library/Taps/homebrew/homebrew – core/Formula/go@1.14.rb’

And you can see that the installation process downloads two compressed packages and executes ‘./make.bash –no-clean’.

/usr/bin/sandbox-exec -f /private/tmp/homebrew20210818-15926-10cv6ja.sb nice ruby -W1 -- / usr/local/Homebrew/Library/Homebrew/build. The rb/usr/local/Homebrew/Library/Taps/Homebrew/Homebrew - core/Formula/go@1.14.rb  --verbose ... tar --extract --no-same-owner --file /Users/huangcheng/Library/Caches/Homebrew/downloads/5ce0f7e2a4821a377e09f2355ce146bf66f8e11bb6fc93320c8146a05198abc6--go 1.14.15. SRC. Tar. Gz -- -- directory/private/TMP/e6dj d20210818-15927-184... tar --extract --no-same-owner --file /Users/huangcheng/Library/Caches/Homebrew/downloads/ad0901a23a51bac69b65f20bbc8e3fe998bc87a3be91d0859ef27bd1fe537709--go 1.7. Darwin - amd64. Tar. Gz - directory/private/TMP/d20210818-15927-1 qdv80h... ==> ./make.bash --no-clean ...Copy the code

Open the rb file and find the code for ‘make. Bash ‘in the SRC directory

    cd "src" do
      ENV["GOROOT_FINAL"] = libexec
      system "./make.bash", "--no-clean"
Copy the code

Find the two packages and unzip them to the make.bash file in the SRC directory. The environment variable is unset -_-!

export GOENV=off
unset GOBIN # Issue 14340
unset GOFLAGS
unset GO111MODULE
Copy the code

How do I set the GO111MODULE

Open the ‘/ usr/local/Homebrew/Library/Taps/Homebrew/Homebrew – core/Formula/go@1.14.rb’ file, find the go build the calling code

. system "go", "build" ...Copy the code

Before executing the code, reset the link variable

. ENV['GOPROXY'] = 'https://goproxy.io,direct' ENV['GO111MODULE'] = 'on' system "go", "build" ...Copy the code

Save and re-execute ‘brew install go@1.14 -v’

==> Summary 🍺 /usr/local/cellar /go@1.14/ 1.14.15:9,471 files, 425.7MB, built in 1 minute 16 secondsCopy the code

Success!