Installing Go 1.12 on MacOS High Sierra

Go 1.12 was released three days ago (Feb 25, 2019). I upgraded my personal MacBook Pro, which runs Mojave, with:

$ brew upgrade go

The upgrade failed with the error:

The upgrade ran fine. Then, I tried to upgrade my work MacBook Pro, which runs High Sierra and sits behind a proxy and plays victim to corporate man-in-the-middle attacks for all network traffic, which creates all sorts of adventures, with the same command:

$ brew upgrade go
go: creating new go.mod: module golang.org/x/tools
build golang.org/x/tools/cmd/godoc: cannot load golang.org/x/net/context/ctxhttp: cannot find module providing package golang.org/x/net/context/ctxhttp

Do not report this issue to Homebrew/brew or Homebrew/core!

Googling uncovered that some packages had moved around, and I saw a note to delete my old Go installation, so I ran:

$ brew remove go

And I deleted:

$GOPATH/src/golang.org
$GOPATH/src/google.golang.org
$GOPATH/pkg

And I still got the same error. Further googling and experimentation netted nothing, so finally I opened Homebrew’s Go installation formula, found at:

/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/go.rb

Actually, on my work Mac, it’s at:

$HOME/.homebrew/Library/Taps/homebrew/homebrew-core/Formula/go.rb

since we don’t have root privileges to install in /usr/local, so that may be the problem but I don’t see how.

Anyway, I could see that Go 1.12 was downloading fine, and the Go bootstrap environment was downloading fine and installing Go, and the problem occurred while installing GoDoc. So I commented out lines 57-66 in the formula:

# Build and install godoc
ENV.prepend_path "PATH", bin
ENV["GO111MODULE"] = "on"
ENV["GOPATH"] = build-path
(buildpath/"src/golang.org/x/tools").install resource("gotools")
cd "src/golang.org/x/tools/cmd/godoc/" do
  system "go", "build"
  (libexec/"bin").install "godoc"
end
bin.install_symlink libexec/"bin/godoc"

And I reran

$ brew install go

And everything worked except I have an old version of godoc in my go/bin directory. If I get around to unraveling the rest of this mystery, I’ll update this post.

Hope this helps someone.

Update Feb 28, 2019 @ 1:45 PM

Having an old version of godoc bothered me, so I did the following:

$ go get -insecure golang.org/x/tools
$ go get -insecure golang.org/x/net
$ cd $GOPATH/src/golang.org/x/tools/cmd/godoc
$ go build
$ go install

The -insecure flag accommodates our corporate proxy; you probably won’t have to do that.

And now my godoc is current.

Update Jan 10, 2020 @ 10:10 AM

Thanks to Josh Hornsby, I now have a real solution and Go upgrades just work ™! Our IT department had indeed deployed the intermediate certificates to our workstations, but they were set to “Use System Defaults” in the “Trust > When using this certificate” section in Keychain Access:

Use System Defaults

Since we aren’t admins on our machines, we couldn’t change that setting. The solution? Export those certificates, import them into the login keychain, and change that setting to “Always Trust.” Now, a simple:

$ brew upgrade go

works as it should.

2 Responses

  1. Michael says:

    Thank you. This post saved me hours! It kept failing to upgrade Go with no good explanation

  2. Michael Dimmitt says:

    Macintosh install instructions for Go.
    Helpful. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.