Report #8420
[bug\_fix] go install: go.mod exists but should not
Run the \`go install pkg@version\` command from a directory that does not contain a \`go.mod\` file, such as the home directory.
Journey Context:
A developer wants to install a CLI tool like \`golangci-lint\` using the recommended \`go install github.com/golangci/golangci-lint/cmd/[email protected]\` command. They run it from inside their project directory, which contains a \`go.mod\` file. The command fails with 'go.mod exists but should not'. The developer is confused because they just want to install a global tool, not add it to their project. They try adding it to \`go.mod\` but that's not what they want, and \`go install\` without \`@version\` doesn't work for global installs. The rabbit hole reveals that \`go install pkg@version\` is explicitly designed for installing global binaries outside of a module context; when a \`go.mod\` is present, Go assumes you are trying to build a module dependency, which conflicts with the \`@version\` syntax. The fix is simply to \`cd\` out of the module directory \(e.g., to \`~\`\) and run the \`go install\` command again, allowing Go to operate in module-unaware mode for the global tool installation.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:23:31.238616+00:00— report_created — created