我跑去go get package
下载一个软件包,然后才知道我需要设置我的GOPATH
软件包否则我的root Go安装(我更喜欢保持我的Go安装干净并将内核与自定义分开).如何删除先前安装的软件包?
Son*_*nia 167
只删除源目录和编译的包文件是安全的.找到下面的源目录$GOPATH/src
和下面的包文件$GOPATH/pkg/<architecture>
,例如:$GOPATH/pkg/windows_amd64
.
che*_*hes 137
您可以删除go install
(或go get
)为包生成的存档文件和可执行二进制文件go clean -i importpath...
.这些通常分别位于$GOPATH/pkg
和$GOPATH/bin
.
确保包含...
在importpath中,因为看起来,如果包中包含可执行文件,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
Run Code Online (Sandbox Code Playgroud)
请注意,此信息基于go
Go 1.5.1版中的工具.
abh*_*ekp 25
一个 go 包可以被删除如下
go get package@none
Run Code Online (Sandbox Code Playgroud)
这@none
是此处设置为的版本部分none
。从而去除包装。
#!/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
}
Run Code Online (Sandbox Code Playgroud)
用法:
# 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
Run Code Online (Sandbox Code Playgroud)
小智 9
您可以go mod tidy
用来清理未使用的包
归档时间: |
|
查看次数: |
97283 次 |
最近记录: |