How to set GOPATH on MAC after installing go1.4.1.darwin-amd64-osx10.8.pkg

huangapple go评论79阅读模式
英文:

How to set GOPATH on MAC after installing go1.4.1.darwin-amd64-osx10.8.pkg

问题

我已经运行了go1.4.1.darwin-amd64-osx10.8.pkg在我的MAC上安装go。它将go安装在/usr/local/go/bin/go目录下。

你能告诉我我的GOPATH应该设置为什么吗?我尝试了'/usr/local/go'和'/usr/local/go/bin/go',但似乎都不是正确的路径。

谢谢。

英文:

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.

答案1

得分: 2

GOPATH是一个环境变量,用于定义工作目录的位置。它被Go工具用于各种目的。

例如:

go get -u github.com/nsf/gocode

  • 将下载源代码并将其放置在$GOPATH/src/github.com/nsfs/gocode
  • 编译该源代码并将二进制文件放置在$GOPATH/bin
  • 将符号和包信息放置在$GOPATH/pkg/architecture/github.com/nsfs

该路径也用于其他工具:

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

上述命令中的github.com/nsfs/gocode会自动解析为$GOPATH/src/github.com/nsfs/gocode,因此您可以在不实际位于工作目录(即$GOPATH)的情况下运行这些命令。

工作目录的$GOPATH位置可以放置在计算机的任何位置,但最少必须有3个文件夹(因为go get和其他工具需要这些文件夹)。

  1. bin
  2. pkg
  3. src

这个环境变量可以像其他环境变量一样设置。如果您正在使用Terminal.app中的go,可以通过打开文件:

vi ~/.bashrc

然后设置它:

export GOPATH=~/goworkplace

~/goworkplace是具有这3个文件夹的工作目录的位置。它可以位于系统的任何位置,例如~/Development/goworkplace~/Desktop/goworkplace,只要它有这3个文件夹。

有关详细信息,请参阅:https://golang.org/doc/code.html

英文:

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

答案2

得分: 1

请尝试以下步骤:

首先,您可以检查是否已安装Golang。运行命令go env

然后,您可以显示Go环境变量的列表。

接下来,检查您可以安装Go的位置。

然后设置**$GOPATH**,例如:export GOPATH=/var/projects/go

还要设置**$GOBIN**,例如:export =$GOPATH/bin

英文:

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

huangapple
  • 本文由 发表于 2015年2月14日 03:46:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/28507568.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定