6

I'm having annoying issue with go install command.

Every time I try to run it within the src directory of my GOPATH the resulted file is getting created in GOROOT/bin directory for some reason.

I verified my environmental variables in .bashrc and also run 'go env' (see below) and couldn't find any issues:

.bashrc

export GOBIN=$HOME/dev/src/go/bin
export GOPATH=$HOME/dev/go-dev
export PATH=$PATH:$GOBIN:$GOPATH/bin

go env

GOARCH="amd64"
GOBIN="/home/user/dev/src/go/bin"
GOCHAR="6"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/dev/go-dev"
GORACE=""
GOROOT="/home/user/dev/src/go"
GOTOOLDIR="/home/user/dev/src/go/pkg/tool/linux_amd64"
CC="gcc"
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
CGO_ENABLED="1"

This post has a similar problem except I have GOPATH in my env (I tried the solution but it didn't help).

When I tried to create the test library using official GoLang site and run go install I've got a proper file created in $GOPATH/pgk/linux_amd64 but not in the bin directory.

Am I missing something in my configuration?

4

1 回答 1

12

关于该go工具的官方文档:

如果 DIR 是 GOPATH 中列出的目录...

如果设置了 GOBIN 环境变量,命令将安装到它命名的目录而不是 DIR/bin

在邮件列表中对此主题进行了讨论,对此进行了进一步解释:

(a) 如果你没有设置你的 GOBIN 环境变量,你会得到 Go 编译器二进制文件进入 GOROOT/bin 而你的二进制文件进入 GOPATH/bin。(我个人喜欢这种二进制文件的分离。)

(b) 如果您将 GOBIN 设置为任何值,那么 Go 二进制文件和您的二进制文件都将转到 GOBIN。

在您的情况下,解决方案是不设置您的GOBIN.

于 2013-07-16T04:17:24.533 回答