dongluojiao6322 2015-02-13 11:46
浏览 101

安装go1.4.1.darwin-amd64-osx10.8.pkg后如何在MAC上设置GOPATH

I have run go1.4.1.darwin-amd64-osx10.8.pkg to install go on my MAC. It install go in /usr/local/go/bin/go.

Can you tell me what should my GOPATH set to? I tried '/usr/local/go' and '/usr/local/go/bin/go'. But both does not seem to be the right path.

Thank you.

  • 写回答

2条回答 默认 最新

  • douzhanbai9526 2015-04-04 17:12
    关注

    GOPATH is an environmental variable used to define the location of your workplace directory. It's used by the Go tools for various reasons.

    For example:

    go get -u github.com/nsf/gocode

    • will download the source code and place it at $GOPATH/src/github.com/nsfs/gocode
    • Compile that source code and place the binary at $GOPATH/bin
    • Place symbol and package information at $GOPATH/pkg/architecture/github.com/nsfs

    The path is also used in other tools:

    • go build github.com/nsf/gocode
    • go install github.com/nsfs/gocode

    github.com/nsfs/gocode in the above commands is resolved automatically to $GOPATH/src/github.com/nsfs/gocode and thus you can run these commands without actually being in your workplace (the point of $GOPATH)

    The $GOPATH location for your workplace directory can be put anywhere on your machine, but it must minimally have 3 folders (because go get and other tools need these folders).

    1. bin
    2. pkg
    3. src

    This environmental variable can be set like any other environmental variable. If you're using go from the Terminal.app, you can set it by opening the file:

    vi ~/.bashrc

    and then setting it

    export GOPATH=~/goworkplace

    ~/goworkplace is a location to the workplace directory with those 3 folders. It can be anywhere on your system, such as, ~/Development/goworkplace, ~/Desktop/goworkplace, as long as it has those 3 folders

    For information, take a look at this: https://golang.org/doc/code.html

    评论
  • doukan5332 2019-06-05 20:25
    关注

    Try this

    First you can check the golang is install or not. Run go env

    After that you can show the list of go env variables..

    then you check where you can install the go

    after that set $GOPATH

    like:- export GOPATH=/var/projects/go

    and also set $GOBIN

    like:- export =$GOPATH/bin

    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部