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 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题