加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

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

发布时间:2020-12-13 19:04:39 所属栏目:Linux 来源:网络整理
导读:我在使用go install命令时遇到了烦人的问题. 每次我尝试在我的GOPATH的src目录中运行它时,由于某种原因,结果文件将在GOROOT / bin目录中创建. 我在.bashrc中验证了我的环境变量,并运行go env'(见下文)并找不到任何问题: 的.bashrc export GOBIN=$HOME/dev/s

我在使用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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读