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

How Can I Manage and Update Go Module Dependencies?

Susan Sarandon
Release: 2025-01-01 12:26:12
Original
812 people have browsed it

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
Copy after login

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
Copy after login

Listing Dependencies with Updates

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

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

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 of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template