删除使用 go get 安装的包

新手上路,请多包涵

我跑了 go get package 下载了一个包,然后才知道我需要设置我的 GOPATH 否则那个包会破坏我的根 Go 安装(我更愿意保持我的 Go 安装干净和独立的核心来自习俗)。如何删除以前安装的软件包?

原文由 Nucleon 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 2.4k
2 个回答

只删除源目录和编译包文件是安全的。找到---下的源码目录和--- $GOPATH/pkg/<architecture> $GOPATH/src 下的包文件,例如: $GOPATH/pkg/windows_amd64

原文由 Sonia 发布,翻译遵循 CC BY-SA 3.0 许可协议

您可以删除 go install (或 go get )为带有 go clean -i importpath... 的包生成的存档文件和可执行二进制文件它们通常分别位于 $GOPATH/pkg$GOPATH/bin 下。

确保在导入路径中包含 ... ,因为看起来,如果一个包包含可执行文件, go clean -i 只会删除它而不是子包的存档文件,例如 gore/gocode 在下面的例子中。

然后需要从 $GOPATH/src 中手动删除源代码。

go clean 有一个 -n 标志用于模拟运行,打印将运行但不执行它的内容,因此您可以确定(参见 go help clean 它还有一个诱人的 -r 递归清理依赖项的标志,你可能不想实际使用它,因为你会从空运行中看到它会删除很多标准库归档文件!

一个完整的示例,您可以根据需要编写脚本:

 $ 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

请注意,此信息基于 Go 版本 1.5.1 中的 go 工具。

原文由 ches 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题