删除随go get安装的软件包


哈哈哈哈
2025-03-18 03:31:47 (21天前)
  1. 我跑了



</跨度>
在得知我需要设置我的GOPATH之前获取包下载包,否则该包会玷污我的root


</跨度>
安装(我更愿意保留我的


</跨度>
从自定义安装干净和独立的核心)。如何删除先前安装的软件包?

4 条回复
  1. 0# 机器设备维修 | 2019-08-31 10-32



    只删除源目录和编译的包文件是安全的。找到下的源目录

    $GOPATH/src

    和包下的文件

    $GOPATH/pkg/

    , 例如:

    $GOPATH/pkg/windows_amd64



  2. 1# 绵绵 | 2019-08-31 10-32



    1.   #!/bin/bash
    2. goclean() {
      local pkg=$1; shift || return 1
      local ost
      local cnt
      local scr

    3. Clean removes object files from package source directories (ignore error)

      go clean -i $pkg &>/dev/null

    4. Set local variables

      [[ $(uname -m)” == x86_64 ]] \
      && ost=”$(uname)”;ost=”${ost,,}_amd64 \
      && cnt=”${pkg//[^\/]}”

    5. 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

    6. Reload the current shell

      source ~/.bashrc
      }

    7. </code>


    用法:



    1.   # Either launch a new terminal and copy `goclean` into the current shell process, 
    2. or create a shell script and add it to the PATH to enable command invocation with bash.

      goclean github.com/your-username/your-repository

    3. </code>

  3. 2# 樱花弄๑•ั็•็ | 2019-08-31 10-32



    您可以删除存档文件和可执行二进制文件

    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

    标志以递归方式清除依赖项,您可能不希望实际使用它,因为您将从干运行中看到它将删除许多标准库存档文件!



    一个完整的示例,如果您愿意,可以将脚本作为基础:




    1. $ go get -u github.com/motemen/gore

    2. $ which gore
      /Users/ches/src/go/bin/gore

    3. $ 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

    4. $ go clean -i github.com/motemen/gore

    5. $ which gore

    6. $ tree $GOPATH/pkg/darwin_amd64/github.com/motemen/gore
      /Users/ches/src/go/pkg/darwin_amd64/github.com/motemen/gore

    7. 0 directories, 0 files

    8. If that empty directory really bugs you

      $ rmdir $GOPATH/pkg/darwin_amd64/github.com/motemen/gore

    9. $ rm -rf $GOPATH/src/github.com/motemen/gore

    10. </code>


    请注意,此信息基于

    go

    Go版本1.5.1中的工具。


登录 后才能参与评论