[Solved] ambiguous import: found package github.com/spf13/cobra/cobra in multiple modules

Quoted articles: https://stackoverflow.com/questions/63710830/spf13-cobra-cant-download-binary-to-gopath-bin

When the package is managed by go mod, it will be downloaded to $gopath/PKG/mod.

When downloading cobra, the executable binary Cobra will be automatically created in the $gopath/bin directory. If the following command line ~ /. Bashrc is added, cobra can be automatically referenced as a command line tool:

export PATH=$PATH:$GOROOT/bin:$GOPATH/bin

However, an error is reported in go get github.com/spf13/cobra/cobra: ambiguous import: found package github.com/spf13/cobra/cobra in multiple modules, indicating that duplicate packages exist. At this time, the solution is to set the version value. The replacement installation command is as follows:

go get -u github.com/spf13/cobra/[email protected]

Read More: