I ran go get package
to download a package before learning that I needed to set my GOPATH
otherwise that package sullies my root Go install (I would much prefer to keep my Go install clean and separate core from custom). How do I remove packages installed previously?
It's safe to just delete the source directory and compiled package file. Find the source directory under $GOPATH/src
and the package file under $GOPATH/pkg/<architecture>
, for example: $GOPATH/pkg/windows_amd64
.
GOPATH
is /usr/lib/go
. –
Pensionary go
–
Mendez A go package can be removed as follows.
go get package@none
Here @none
is the version part set as none
. Thus removing the package.
~/go/bin
, but package still remains in ~/go/pkg/mod/github.com/...
. Is there another step? –
Kickback ~/go/bin
for me. no errors, no output from the command. –
Berny go clean -cache -modcache
. –
Monjo go mod tidy
from the Blog. –
Kickback ko
) –
Lowndes uninstall
–
Drainpipe go.sum
. Need go mod tidy
for it –
Piperine go install
, but go install ...@none
doesn't work. go install
installs just a binary, so rm "$(which package-name)"
is enough. –
Russell It's safe to just delete the source directory and compiled package file. Find the source directory under $GOPATH/src
and the package file under $GOPATH/pkg/<architecture>
, for example: $GOPATH/pkg/windows_amd64
.
GOPATH
is /usr/lib/go
. –
Pensionary go
–
Mendez You can delete the archive files and executable binaries that go install
(or go get
) produces for a package with go clean -i importpath...
. These normally reside under $GOPATH/pkg
and $GOPATH/bin
, respectively.
Be sure to include ...
on the importpath, since it appears that, if a package includes an executable, go clean -i
will only remove that and not archive files for subpackages, like gore/gocode
in the example below.
Source code then needs to be removed manually from $GOPATH/src
.
go clean
has an -n
flag for a dry run that prints what will be run without executing it, so you can be certain (see go help clean
). It also has a tempting -r
flag to recursively clean dependencies, which you probably don't want to actually use since you'll see from a dry run that it will delete lots of standard library archive files!
A complete example, which you could base a script on if you like:
$ go get -u github.com/motemen/gore
$ which gore
/Users/ches/src/go/bin/gore
$ go clean -i -n github.com/motemen/gore...
cd /Users/ches/src/go/src/github.com/motemen/gore
rm -f gore gore.exe gore.test gore.test.exe commands commands.exe commands_test commands_test.exe complete complete.exe complete_test complete_test.exe debug debug.exe helpers_test helpers_test.exe liner liner.exe log log.exe main main.exe node node.exe node_test node_test.exe quickfix quickfix.exe session_test session_test.exe terminal_unix terminal_unix.exe terminal_windows terminal_windows.exe utils utils.exe
rm -f /Users/ches/src/go/bin/gore
cd /Users/ches/src/go/src/github.com/motemen/gore/gocode
rm -f gocode.test gocode.test.exe
rm -f /Users/ches/src/go/pkg/darwin_amd64/github.com/motemen/gore/gocode.a
$ go clean -i github.com/motemen/gore...
$ which gore
$ tree $GOPATH/pkg/darwin_amd64/github.com/motemen/gore
/Users/ches/src/go/pkg/darwin_amd64/github.com/motemen/gore
0 directories, 0 files
# If that empty directory really bugs you...
$ rmdir $GOPATH/pkg/darwin_amd64/github.com/motemen/gore
$ rm -rf $GOPATH/src/github.com/motemen/gore
Note that this information is based on the go
tool in Go version 1.5.1.
-r
flag. But beware - if a dependency is used by some other package, it will still get deleted. –
Homespun go install foo@latest
) package. –
Embrey You can use go mod tidy
to clean unused packages
#!/bin/bash
goclean() {
local pkg=$1; shift || return 1
local ost
local cnt
local scr
# Clean removes object files from package source directories (ignore error)
go clean -i $pkg &>/dev/null
# Set local variables
[[ "$(uname -m)" == "x86_64" ]] \
&& ost="$(uname)";ost="${ost,,}_amd64" \
&& cnt="${pkg//[^\/]}"
# Delete the source directory and compiled package directory(ies)
if (("${#cnt}" == "2")); then
rm -rf "${GOPATH%%:*}/src/${pkg%/*}"
rm -rf "${GOPATH%%:*}/pkg/${ost}/${pkg%/*}"
elif (("${#cnt}" > "2")); then
rm -rf "${GOPATH%%:*}/src/${pkg%/*/*}"
rm -rf "${GOPATH%%:*}/pkg/${ost}/${pkg%/*/*}"
fi
# Reload the current shell
source ~/.bashrc
}
Usage:
# Either launch a new terminal and copy `goclean` into the current shell process,
# or create a shell script and add it to the PATH to enable command invocation with bash.
goclean github.com/your-username/your-repository
I deleted the whole go folder in my home directory and then with go mod tidy
I redownloaded all dependencies actually used by my project (I had a bunch of old versions in addition to the actual versions used).
I recovered about 3GB of disk space.
go clean -modcache
will do the trick for you
Man, i got same problem yesterday. Could't find anything in $GOPATH/pkg/<architecture>
. Then, i realized that there was a go directory in my $HOME. So, i moved to $HOME/<username>/go/pkg/mod/github.com
and saw all package i had installed from github by go get
© 2022 - 2024 — McMap. All rights reserved.
go get example.com/mod@none
fromgo help get
– Chiromancy