[go] go get으로 설치된 패키지 제거

루트 Go 설치에 적합하지 않은 패키지 go get package를 설정해야한다는 것을 배우기 전에 패키지를 다운로드하기 위해 달려갔습니다 GOPATH. 이전에 설치된 패키지를 어떻게 제거합니까?



답변

소스 디렉토리와 컴파일 된 패키지 파일을 삭제하는 것이 안전합니다. 아래에서 소스 디렉토리를 찾고 아래 $GOPATH/src에서 패키지 파일을 찾으십시오 ( $GOPATH/pkg/<architecture>예 🙂 $GOPATH/pkg/windows_amd64.


답변

당신은 아카이브 파일 것을 실행 바이너리를 삭제할 수 있습니다 go install(또는 go get)와 패키지 생산을 go clean -i importpath.... 이들은 일반적으로 $GOPATH/pkg및 아래 $GOPATH/bin에 있습니다.

...패키지에 실행 파일이 포함 된 경우 아래 예 go clean -i와 같이 하위 패키지에 대한 파일을 아카이브하지 않고 제거 할 것이므로 importpath 에 포함시켜야 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

이 정보는 goGo 버전 1.5.1 의 도구를 기반으로합니다 .


답변

#!/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
}

용법:

# 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


답변