dsw7547 2016-03-10 15:53
浏览 123
已采纳

如何确认正确设置了$ GOPATH和$ GOROOT?

This is not a repeat of this question:

what should be the values of GOPATH and GOROOT?

I don't want to know what the values should be. I want to know what I should see when I type ls $GOROOT or ls $GOPATH into console. I'm pretty sure I set things up wrong following a tutorial almost a year ago, and I want to be able to confirm that these two are pointing to where they should be by simply checking that what they point to looks right.

Here's where I am right now. It looks like $GOROOT is pointing nowhere. I'm pretty sure it should be pointing at usr/local/go, but it would be a lot easier to confirm if I knew what the expected result of ls $GOROOT is supposed to be.

As for $GOPATH I'm not totally sure if my "workspace" is where all my go code is, or maybe just the github stuff, or maybe the particular folder I'm working within. I know it's supposed to point to my "work space," but I don't know what that work space I'm looking for looks like.

Sephs-MBP:ThumbzArt seph$ $GOROOT
Sephs-MBP:ThumbzArt seph$ $GOPATH
-bash: /Users/seph/code/golang: is a directory
Sephs-MBP:ThumbzArt seph$ ls $GOROOT
Bman.jpg            README.md           ThumbzArt.sublime-workspacescripts              thumbzart.go
LICENSE.md          ThumbzArt.sublime-project   public              templates           ticktock.go
Sephs-MBP:ThumbzArt seph$ $GOPATH
-bash: /Users/seph/code/golang: is a directory
Sephs-MBP:ThumbzArt seph$ ls $GOPATH
-   bin p   pkg src
Sephs-MBP:ThumbzArt seph$ ls /usr/local/go
AUTHORS     CONTRIBUTORS    PATENTS     VERSION     bin     doc     lib     pkg     src
CONTRIBUTING.md LICENSE     README.md   api     blog        favicon.ico misc        robots.txt  test
Sephs-MBP:ThumbzArt seph$ 

I know this question seems ridiculous, but it's hard to confirm things for which you have no expected results.

Thank you

Sephs-MBP:streak seph$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/seph/code/golang"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT=""
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

Sephs-MBP:streak seph$ go version
go version go1.5.2 darwin/amd64

Sephs-MBP:streak seph$ which go
/usr/local/go/bin/go
  • 写回答

1条回答 默认 最新

  • doufenpaiyu63706 2016-03-10 16:26
    关注

    EDIT: Another very useful feature I just stumbled across is this: go help gopath. This should have probably been somebodies answer.

    The folder $GOPATH points to should like this:

    Sephs-MBP:streak seph$ ls $GOPATH
    -   bin p   pkg src
    

    $GOROOT, on the other hand, will yield unexpected results if you use ls $GOROOT as compared to ls $GOPATH. This is because $GOROOT is not set within this context, I think.

    Sephs-MBP:helloworld seph$ ls $GOROOT
    helloworld.go
    

    If you use go env you'll see the true nature of $GOROOT

    Sephs-MBP:streak seph$ go env
    GOARCH="amd64"
    GOBIN=""
    GOEXE=""
    GOHOSTARCH="amd64"
    GOHOSTOS="darwin"
    GOOS="darwin"
    GOPATH="/Users/seph/code/golang"
    GORACE=""
    GOROOT="/usr/local/go"            //this is where it actually points
    GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
    GO15VENDOREXPERIMENT=""
    CC="clang"
    GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-    arguments -fmessage-length=0 -fno-common"
    CXX="clang++"
    CGO_ENABLED="1"
    

    And if you get the result of $GOROOT from go env and do ls you should see something like this:

    Sephs-MBP:streak seph$ ls /usr/local/go
    AUTHORS     CONTRIBUTORS    PATENTS     VERSION     bin     doc         lib     pkg     src
    CONTRIBUTING.md LICENSE     README.md   api     blog        favicon.ico misc        robots.txt  test
    

    If all of these things check out, then your $GOPATH and $GOROOT are properly set.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 麒麟V10桌面版SP1如何配置bonding
  • ¥15 Marscode IDE 如何预览新建的 HTML 文件
  • ¥15 K8S部署二进制集群过程中calico一直报错
  • ¥15 java python或者任何一种编程语言复刻一个网页
  • ¥20 如何通过代码传输视频到亚马逊平台
  • ¥15 php查询mysql数据库并显示至下拉列表中
  • ¥15 freertos下使用外部中断失效
  • ¥15 输入的char字符转为int类型,不是对应的ascall码,如何才能使之转换为对应ascall码?或者使输入的char字符可以正常与其他字符比较?
  • ¥15 devserver配置完 启动服务 无法访问static上的资源
  • ¥15 解决websocket跟c#客户端通信