linux – go install总是使用GOROOT / bin而不是GOPATH

前端之家收集整理的这篇文章主要介绍了linux – go install总是使用GOROOT / bin而不是GOPATH前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我在使用go install命令时遇到了烦人的问题.

每次我尝试在我的GOPATH的src目录中运行它时,由于某种原因,结果文件将在GOROOT / bin目录中创建.

我在.bashrc中验证了我的环境变量,并运行’go env'(见下文)并找不到任何问题:

的.bashrc

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

去环境

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有一个类似的问题,除了我在我的环境中有GOPATH(我尝试了解决方案,但它没有帮助).

当我尝试创建测试库using official GoLang site并运行go install时,我在$GOPATH / pgk / linux_amd64中创建了一个正确的文件,但是没有在bin目录中创建.

我在配置中遗漏了什么吗?

最佳答案
Official documentation关于go工具:

If DIR is a directory listed in the GOPATH…

If the GOBIN environment variable is set,commands are installed to the directory it names instead of DIR/bin

关于这个主题的讨论在mailing list进行了进一步的解释:

(a) If you don’t set your GOBIN env variable,
you get the Go compiler binaries going in GOROOT/bin
whereas the your binaries are going in GOPATH/bin.
(I personally like this separation of binaries.)

(b) If you set your GOBIN to anything,then
both the Go binaries and your binaries are going to GOBIN.

你的案例中的解决方案是不设置你的GOBIN.

原文链接:https://www.f2er.com/linux/440303.html

猜你在找的Linux相关文章