首页 文章

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

提问于
浏览
-2

这不是这个问题的重复:

what should be the values of GOPATH and GOROOT?

我不想知道这些值应该是什么 . 我想知道当我输入 ls $GOROOTls $GOPATH 进入控制台时我应该看到什么 . 我很确定我在大约一年前的教程后设置错误了,我希望能够通过简单地检查它们指向正确的内容来确认这两个指向它们应该在哪里 .

这就是我现在所处的位置 . 看起来 $GOROOT 指向无处 . 我很确定它应该指向 usr/local/go ,但要确认我是否知道 ls $GOROOT 的预期结果应该更容易 .

至于 $GOPATH 我'm not totally sure if my 2372777 is where all my go code is, or maybe just the github stuff, or maybe the particular folder I'在其中工作 . 我知道's supposed to point to my 2372778 but I don'知道我正在寻找的工作空间是什么样的 .

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$

我知道这个问题看起来很荒谬,但很难确定你没有预期结果的事情 .

谢谢

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 回答

  • -5

    编辑:我偶然发现的另一个非常有用的功能是: go help gopath . 这可能是某些人的回答 .

    $GOPATH 指向的文件夹应该是这样的:

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

    另一方面,如果使用 ls $GOROOTls $GOPATH 相比, $GOROOT 将产生意外结果 . 这是因为我认为 $GOROOT 未在此上下文中设置 .

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

    如果您使用 go env ,您将看到 $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"
    

    如果你从 go env 得到 $GOROOT 的结果并且做 ls 你应该看到这样的东西:

    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
    

    如果所有这些都检查出来,那么 $GOPATH$GOROOT 已正确设置 .

相关问题