-1

I came back to golang after a while, and tried to troubleshoot an open source library.

When I tried to install its dependencies, and even when my IDE (VSCode) tried to install the current language server, I would get errors like the following:

$ go install -v golang.org/x/tools/gopls@latest
go: golang.org/x/tools/gopls@latest: module golang.org/x/tools/gopls: reading https://gocenter.io/golang.org/x/tools/gopls/@v/list: 405 Not Allowed

In an attempt to troubleshoot this, I created another user on my machine and the dependency installation worked when I used that user account.

What is going on?
Why can I no longer install any package with go?

MasterAM
  • 16,283
  • 6
  • 45
  • 66

1 Answers1

1

The go module system can use a proxy protocol to fetch dependencies. The proxies that are being used are controlled by go's GOPROXY environment variable.

Its default value in the past likely included goceter.io, which was a service offered by JFrog and was discontinued at some point.

$ go env GOPROXY
gocenter.io,goproxy.io,goproxy.cn,proxy.golang.org,direct
$ cat "$(go env GOENV)"
GOPROXY=gocenter.io,goproxy.io,goproxy.cn,proxy.golang.org,direct

In my case, it was being set in the file pointed by go env GOENV, and removing this domain (and others) from the file contents made everything work again.

$ vim "$(go env GOENV)"
# (edit the file using your favorite editor)
$ cat "$(go env GOENV)"
GOPROXY=proxy.golang.org,direct
$ go env GOPROXY
proxy.golang.org,direct
# now gocenter.io is no longer there
$ go install -v golang.org/x/tools/gopls@latest
go: downloading golang.org/x/tools/gopls v0.9.5
go: downloading golang.org/x/tools v0.2.0
# ...
MasterAM
  • 16,283
  • 6
  • 45
  • 66