Skip to content

cmd/go: go clean doesn't remove binaries installed by go install module@version #65687

@Rican7

Description

@Rican7

Go version

go version go1.21.7 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/tnsuarez/Library/Caches/go-build'
GOENV='/Users/tnsuarez/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/tnsuarez/Development/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/tnsuarez/Development/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.21.7/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.21.7/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.7'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/gd/n720k8816r7c0bnv44nb9crw0000gp/T/go-build4251940867=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

I installed a binary via go install and then was unable to use the same tool to uninstall/clean the installed package binary.

I had to manually remove the binary via rm.

What did you see happen?

~ $ go install github.com/Rican7/define@latest
~ $ which define
/Users/tnsuarez/Development/go/bin/define
~ $ go clean github.com/Rican7/define@latest
package github.com/Rican7/define@latest: can only use path@version syntax with 'go get' and 'go install' in module-aware mode
~ $ go clean github.com/Rican7/define
no required module provides package github.com/Rican7/define: go.mod file not found in current directory or any parent directory; see 'go help modules'
~ $ go clean -i github.com/Rican7/define
no required module provides package github.com/Rican7/define: go.mod file not found in current directory or any parent directory; see 'go help modules'
~ $ go clean -i github.com/Rican7/define@latest
package github.com/Rican7/define@latest: can only use path@version syntax with 'go get' and 'go install' in module-aware mode

What did you expect to see?

I expected that a go clean github.com/Rican7/define would remove the package binary that it had installed.

It would likely make sense to have the command maybe be go clean -i github.com/Rican7/define@latest, but maybe the version suffix is awkward?

The version suffix is what changes the behavior of go install to no longer consider the current module (go.mod) defined version, so there would be symmetry there, but also having to specify the version to uninstall might be awkward.

I couldn't find anything related to this, beyond maybe #50261.

Also, a quick search shows that there seems to be a lot of confusion around this very (lack of?) behavior:

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions