today-i-learnt

Pin a golang dependency to a specific version

Category golang
Added on 2026-05-21
Source source

In Go just updating the dependency version in go.mod is not enough, as the algorithm would select the minimum compatible version, which may not be the one we want.

To pin it, use a replace directive in go.mod, forcing dependency resolution to use the specified version.

replace github.com/repo/dep => github.com/repo/dep v1.20.7