Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pin version with go get

I 'd like to pin the version of one package, so whenever I run

go get -u ./...

..this package would stay unchanged (but the rest refreshed normally).

like image 579
vbence Avatar asked Dec 11 '25 18:12

vbence


1 Answers

If you want to pin specific version for a particular Go package, then it can be done via replace directive. For example, the following go.mod config pins golang.org/x/exp to v0.0.0-20230713183714-613f0c0eb8a1, so go get -u -d ./... doesn't updated this package to newer version:

module github.com/myname/mymodule

replace golang.org/x/exp => golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1

require (
  ...
  // This version is updated with go get -u -d ./..., but it is always
  // overridden by the version specified in the replace directive above
  golang.org/x/exp v0.0.0-20231006140011-7918f672742d
  ...
)
like image 61
valyala Avatar answered Dec 13 '25 07:12

valyala