Home >Backend Development >Golang >How to Install Go Tools with Go Modules Without Modifying go.mod?
Installing Go Tools with Go Modules
When using Go modules for dependency management, attempting to install a tool may result in an error if no main module is found.
To resolve this issue, consider the following scenarios:
Scenario 1: Installing Tools Without Modifying go.mod
If you don't want to track the tool as a dependency in your current module, here are two options:
$ cd /tmp $ go get github.com/some/[email protected]
$ go install golang.org/x/tools/cmd/stringer
Scenario 2: Tracking Tools as Dependencies in go.mod
To explicitly track a tool as a dependency in your go.mod:
//go:build tools // +build tools package tools import ( _ "golang.org/x/tools/cmd/stringer" )
The above is the detailed content of How to Install Go Tools with Go Modules Without Modifying go.mod?. For more information, please follow other related articles on the PHP Chinese website!