douduiwei2831
2013-04-06 04:09
浏览 306
已采纳

go install始终尝试使用GOROOT,而go env下未列出GOPATH

I'm having a quite frustrating problem with the GOPATH, which, despite being set in .profile, is not appearing when invoking go env, and does not appear to be affecting the go install target location.

I'm attempting to use go install to install packages, and am getting this error, which clearly shows that it is attempting to install in /usr/lib/go, rather than the intended directory of /home/me/dev/go.

$ go install github.com/songgao/colorgo
go install github.com/songgao/go.pipeline: mkdir /usr/lib/go/pkg/linux_386/github.com: permission denied

go env gives the following results.

$ go env
GOROOT="/usr/lib/go"
GOBIN=""
GOARCH="386"
GOCHAR="8"
GOOS="linux"
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_386"
GOGCCFLAGS="-g -O2 -fPIC -m32 -pthread"
CGO_ENABLED="1"

But it most certainly is set.

$ echo $GOPATH
/home/me/dev/go

Update: I have exported GOPATH in ~/.profile and sourced it, but I'm still having the same problem.

$ export GOPATH=/home/me/dev/go
$ go env
GOROOT="/usr/lib/go"
GOBIN=""
GOARCH="386"
GOCHAR="8"
GOOS="linux"
GOEXE=""
GOHOSTARCH="386"
GOHOSTOS="linux"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_386"
GOGCCFLAGS="-g -O2 -fPIC -m32 -pthread"
CGO_ENABLED="1"

Update again: This problem has ceased since I upgraded to go1.1beta2. I'm not sure what was wrong, because GOPATH appeared to be set correctly, but it's all apparently working now.

图片转代码服务由CSDN问答提供 功能建议

我在使用 GOPATH 时遇到了令人沮丧的问题,尽管设置了 在 .profile 中,调用 go env 时不会出现,并且似乎不会影响 go install 目标位置。

我正在尝试使用 go install 来安装软件包,并且收到此错误,该错误清楚地表明它正在尝试将其安装在 / usr / lib /中 ,而不是 / home / me / dev / go 的预期目录。

  $ go install github.com/songgao  / colorgo 
go安装github.com/songgao/go.pipeline:mkdir /usr/lib/go/pkg/linux_386/github.com:权限被拒绝
   
 
 

go env 给出以下结果。

  $ go env 
GOROOT =“ / usr / lib / go” 
GOBIN =“” 
GOARCH =  “386” 
GOCHAR = “8” 
GOOS = “linux的” 
GOEXE = “” 
GOHOSTARCH = “386” 
GOHOSTOS = “linux的” 
GOTOOLDIR = “/ usr / lib中/去/包装/工具/ linux_386” \  nGOGCCFLAGS =“-g -O2  -fPIC -m32 -pthread“ 
CGO_ENABLED =” 1“ 
   
 
 

,但肯定可以确定已设置

  $ echo $ GOPATH 
 / home / me / dev / go 
   
 
 

更新:〜/ .profile 中导出GOPATH并将其来源,但是我仍然遇到相同的问题。

  $ export GOPATH = / home / me  / dev / go 
 $ go env 
GOROOT =“ / usr / lib / go” 
GOBIN =“” 
GOARCH =“ 386” 
GOCHAR =“ 8” 
GOOS =“ linux” 
GOEXE =“” 
GOHOSTARCH  =“ 386” 
GOHOSTOS =“ linux” 
GOTOOLDIR =“ / usr / lib / go / pkg / tool / linux_386” 
GOGCCFLAGS =“-g -O2 -fPIC -m32 -pthread” 
CGO_ENABLED =“ 1” 
    
 
 

再次更新:自从我升级到go1.1beta2以来,此问题已不再存在。 我不确定发生了什么问题,因为 GOPATH 似乎设置正确,但现在看来一切正常。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

4条回答 默认 最新

  • dongwei8440 2013-04-06 04:16
    最佳回答

    GOPATH and workspaces

    $ mkdir -p $HOME/dev/go/src
    $ mkdir -p $HOME/dev/go/bin
    

    In $HOME/.profile:

    export GOPATH=$HOME/dev/go:
    export PATH=$PATH:$HOME/dev/go/bin
    

    Then reboot or log out and log in.

    As soon as you have logged in, before anything else, run:

    $ env | grep -i '^GO'
    GOPATH=/home/me/dev/go
    $ cat $HOME/.profile
    

    What output do you get?

    评论
    解决 无用
    打赏 举报
查看更多回答(3条)

相关推荐 更多相似问题