duanou2016 2014-11-06 06:39
浏览 294
已采纳

osx-`go get`失败,对某些go软件包的权限被拒绝

Installing some go packages fails with permission denied error, eg.:

$ go get code.google.com/p/go.tools/cmd/cover
go install code.google.com/p/go.tools/cmd/cover: open /usr/local/go/pkg/tool/darwin_amd64/cover: permission denied

When I tried using sudo to fix the permission issue, it failed with $GOPATH not set error:

$ sudo go get code.google.com/p/go.tools/cmd/cover
Password:
package code.google.com/p/go.tools/cmd/cover: cannot download, $GOPATH not set. For more details see: go help gopath

How can I solve this?

  • 写回答

2条回答 默认 最新

  • dongmacuo1193 2014-11-06 06:39
    关注
    1. The godoc, go tool vet, go tool cover etc. are special go.tools commands that are meant to be installed into the system path by default with the go binary. If these commands are not available, you should try reinstall go itself (or find go.tools in your packaging system).

      Note: On OS X 10.8+, try installing go using Homebrew instead of the official .pkg installer and your troubles should be gone (as of go 1.4): brew install go

    2. If you want to download a specific pkg into your $GOPATH (eg. 3rd party dependency), use go get -d <pkg> instead. Example:

      go get -d code.google.com/p/go.tools/cmd/cover
      
    3. You shouldn't need to use the sudo hammer at all, as your $GOPATH should point to a directory that you own, and thus no permission: denied error at all.

      But if you really know what you're doing, and you still want to sudo install something, you need to edit the sudoers file first to fix the root's GOPATH:

      $ sudo visudo
      

      add the following line:

      Defaults    env_keep += "GOPATH"
      

      This will make the sudo go get (root context) pick up your $GOPATH value.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python