Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between `go get ...` and `go get -u ...`?

Tags:

go

In go mod, what is the difference between go get ... and go get -u ... commands?

like image 299
desenV Avatar asked Dec 06 '25 02:12

desenV


1 Answers

You would use -u to update the dependencies to their latest available minor and patch versions. So if your module is using package foo.com/bar, running go get -u foo.com/bar will update not only foo.com/bar to the latest MINOR.PATCH, but also its dependencies.

Go modules follows semver: MAJOR.MINOR.PATCH

Changes in MINOR and PATCH should never break users, so they are "safe" to automatically update. That said, the conservative approach (without -u) doesn't update them and is appropriate in some cases.


An interesting quote from the modules wiki:

A common mistake is thinking go get -u foo solely gets the latest version of foo. In actuality, the -u in go get -u foo or go get -u foo@latest means to also get the latest versions for all of the direct and indirect dependencies of foo. A common starting point when upgrading foo is instead to do go get foo or go get foo@latest without a -u (and after things are working, consider go get -u=patch foo, go get -u=patch, go get -u foo, or go get -u).

like image 136
Eli Bendersky Avatar answered Dec 08 '25 14:12

Eli Bendersky



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!