Home >Backend Development >Golang >How Can I Manage and Update Go Module Dependencies?

How Can I Manage and Update Go Module Dependencies?

Susan Sarandon
Susan SarandonOriginal
2025-01-01 12:26:12779browse

How Can I Manage and Update Go Module Dependencies?

Go Mod Dependency Management

Similar to the npm-outdated command in Node.js, Go mod provides several options for managing and updating project dependencies.

Listing All Dependencies (Direct and Indirect)

To list all available minor and patch updates for both direct and indirect dependencies, run the following command:

go list -u -m all

This will provide a report of all outdated dependencies.

Listing Only Direct Dependencies

If you only want to see the outdated dependencies of your current project (direct dependencies), you can use a custom output format to filter out indirect dependencies:

go list -u -m -f '{{if not .Indirect}}{{.}}{{end}}' all

Listing Dependencies with Updates

To only list dependencies that have available updates, use this command:

go list -u -m -f '{{if .Update}}{{.}}{{end}}' all

External Tools

In addition to the built-in Go mod commands, there is also a third-party app called go-mod-outdated that provides a table view of outdated dependencies with filtering options.

Additional Resources

  • [Command go: List packages or modules](https://go.dev/ref/mod#cmd-go-list)
  • [Go 1.11 Modules: How to Upgrade and Downgrade Dependencies wiki](https://github.com/golang/go/wiki/Modules#how-to-upgrade-and-downgrade-dependencies)
  • [go-mod-outdated](https://github.com/psampaz/go-mod-outdated)

The above is the detailed content of How Can I Manage and Update Go Module Dependencies?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn