Go CLI Modules and Workspaces/Add require directive

Add an explicit module requirement.

Section: Editing and Replacements

Add require directive

bash
bash
go mod edit -require example.com/lib@v1.2.3
Explanation

Add an explicit module requirement. Useful in Go CLI workflows.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Editing and Replacements
Add replace directive
Point a module dependency to a local checkout.
OpenIn sheetbashsame section
Set go line
Set the minimum Go version in go.mod.
OpenIn sheetbashsame section
Vendor dependencies
Copy dependencies into a vendor directory.
OpenIn sheetbashsame section
Inspect current module JSON
Inspect current module metadata.
OpenIn sheetbashsame section
Initialize module
Create a new go.mod for the current project.
OpenIn sheetbash2 tag match
Tidy dependencies
Add missing and remove unused module requirements.
OpenIn sheetbash2 tag match