SoFunction
Updated on 2025-04-11

Go: Several ways to automatically upgrade dependent versions

In Go language projects, dependency management uses Go Modules (and). If you want to automatically upgrade your dependencies, you can use the following methods.

1. Method 1: Upgrade all dependencies

go get -u ./...

🔹 Function:

  • -u: Upgrade all Go dependencies to the latest minor version (minor) or patch version (patch).
  • ./...: Upgrade all dependencies within the project.

2. Method 2: Upgrade the specified dependency

go get -u /gin-gonic/gin

🔹 Function:

  • Upgrade only/gin-gonic/ginThis depends on the latest version.

If you need to upgrade to the latest major version, you need to specifyvX

go get -u /gin-gonic/gin@v2

3. Method 3: Upgrade all dependencies to the latest major version

defaultgo get -uUpgrade onlyminorandpatchVersion, if you want to upgrade to the latestmajorVersion, can be used:

go get -u -t -d ./...
  • -u: Upgrade all dependencies
  • -t: Includes test dependencies
  • -d: Only download dependencies, not compile

🚀 Automatically upgrade to the latest version (including the Major version):

go list -m -u all

4. Method 4: Clean up useless dependencies

After upgrading the dependency, there may be useless dependencies, and you can use:

go mod tidy

5. Method 5: Use Renovate or Dependabot to automatically manage

📌 Automatically upgrade the Go dependencies of GitHub repository

If your project is hosted on GitHub, you can use:

6. Method 6: Manually edit and upgrade

If you want to manually specify the dependency version:

go get /gin-gonic/[email protected]

Or edit directly

Then run:

go mod tidy
go mod download

7. Method 7: Upgrade Go version

If your Go version is too old, you can upgrade the Go version:

go install /dl/go1.21@latest
go1.21 download

Then recompile:

go mod tidy
go mod download

🔥 Summary

method effect
go get -u ./... Upgrade all dependencies (minor & patch)
go get -u package_name Upgrade the specified dependency
go get -u -t -d ./... Upgrade all dependencies to the latest major version
go list -m -u all View upgradeable dependencies
go mod tidy Clean up useless dependencies
Renovate / Dependabot Automatically upgrade GitHub
Manual edit Directly specify the dependency version

🚀 Best practices

  • Rungo get -u ./...Upgrade dependencies
  • usego list -m -u allView upgradeablemajorVersion
  • Rungo mod tidyClean up dependencies
  • Use Renovate in CI/CD to automatically manage dependency upgrades

This way, you can keep Go dependencies up to date to ensure project stability and security! 🔥

This is the end of this article about the implementation of Go automatic upgrade dependent version. For more related contents of Go automatic upgrade dependent version, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!