Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"go mod tidy" will auto upgrade go version in go.mod?

Tags:

go

go-modules

Previously the project was using go 1.20 in go.mod. I've upgrade my go version to 1.21.0 on local linux machine.

When I run go mod tidy for the project, it upgraded go.mod to use go 1.21.0 automatically.

If this is the expected behavior, is there a way to disable this behaviour, aka. don't auto update the go version in go.mod when run go mod tidy? Because others might didn't upgrade locally yet.

like image 857
user218867 Avatar asked Dec 05 '25 20:12

user218867


1 Answers

The go mod tidy command does not (currently) alter the go directive in go.mod based only on the local toolchain version. It sets it based on dependencies, and does not need to track patch versions.

If you have a dependency that requires a minimum of go1.21, then your module requires go1.21, forcing the go tool to update the go directive in go.mod accordingly. It would not be of any use to have your module declare a version prior to go1.21 when go1.21 is actually required to build the module.

like image 80
JimB Avatar answered Dec 07 '25 16:12

JimB



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!