Published on 2025-02-18
I had an issue with Go tools around versioning, and here's how I solved it. It could be useful to others. This was the error:
$ staticcheck ./...
-: module requires at least go1.23.6, but Staticcheck was built with go1.23.1 (compile)
$ go version
go version go1.23.6 linux/amd64
Indeed the project was specifying go 1.23.6
in go.mod
.
Even after removing the staticcheck binary and re-installing it I still had the same issue:
$ which staticcheck
/home/pg/go/bin/staticcheck
$ rm /home/pg/go/bin/staticcheck
$ which staticcheck
which: no staticcheck
$ go install honnef.co/go/tools/cmd/staticcheck@v0.5.1
$ staticcheck ./...
-: module requires at least go1.23.6, but Staticcheck was built with go1.23.1 (compile)
I even tried the -a
flag for go install
to force a clean build (since go install
fetches the sources and builds them) to no avail.
Solution: following https://go.dev/doc/manage-install, I installed the specific version of Go I needed and used that to install the tool:
$ go install golang.org/dl/go1.23.6@latest
$ go1.23.6 download
$ go1.23.6 install honnef.co/go/tools/cmd/staticcheck@v0.5.1
$ staticcheck -tags=integration_tests ./... # Works!
That was a TIL for me.
Note that Go 1.24 supports the project listing tools directly in go.mod
which would probably solve this issue directly.
If you enjoy what you're reading, you want to support me, and can afford it: Support me. That allows me to write more cool articles!
This blog is open-source! If you find a problem, please open a Github issue. The content of this blog as well as the code snippets are under the BSD-3 License which I also usually use for all my personal projects. It's basically free for every use but you have to mention me as the original author.