英文:
Go Binary Installed Through "Go Install" command outputs nothing
问题
上下文:
我按照这个关于构建和安装Go二进制文件的教程进行操作。在这之前,我相信我已经正确地按照了之前的每个教程。
这是我编写的基本主包,它调用了相邻目录中的包。
如教程中所指示,我还将我的go二进制输出路径添加到了PATH变量中:
/home/exampleuser/go/bin
同样,按照指示,我进入了我的go主包目录,并运行了以下命令:
$ go build
$ go install
并且如文档中所说,这确实将二进制文件放在了$GOBIN路径中,该路径也已添加到了路径变量中:
期望结果:
如果./caller
是二进制文件,在安装后,无论在哪个目录中,我都应该得到与使用go run
运行.go文件时得到的响应相同的结果:
$ caller
>> map[SysAdmin:Great to see you, SysAdmin! CloudBender:Hail CloudBender, well met! Engineer:Hail Engineer, well met!]
实际输出:
$ caller
>>
附注
我不确定在运行go env
命令时是否应该打印出所有的环境变量,例如当我尝试打印$GOBIN时,我得到了一个空输出。
英文:
Context:
This go tutorial on building and installing Go binaries is what I followed. Until this one, I believe I've correctly followed every tutorial that comes before.
Here's a look at the basic main package that I wrote that calls packages from then neighboring directories.
As instructed in that tutorial, I also added to the PATH variable, my go binary output path:
/home/exampleuser/go/bin
Again, as instructed, I cd'd to my go main package directory and ran the following commands:
$ go build
$ go install
And as said in the documentation this did put the binary in the $GOBIN path which again has been added to the path variable:
Expectation:
If ./caller
is the binary, after installing it, from any directory I should get the response as obtained by running the .go file with go run
:
$ caller
>> map[SysAdmin:Great to see you, SysAdmin! CloudBender:Hail CloudBender, well met! Engineer:Hail Engineer, well met!]
Actual Output:
$ caller
>>
PS
I am not sure if all the environment variables seen on running the go env
command, are supposed to be printed out when echoed like: echo $<GO ENV VARIABLE>
. For example when I tried echoing $GOBIN, I get a blank output.
答案1
得分: -2
感谢这个帖子。如帖子中所说,我尝试首先设置$GOPATH,然后在$PATH中引用它,并设置$GOBIN,并通过sourcing ~/.bashrc来实现所有这些。
此外,我稍微更改了我的模块名称,然后构建和安装它。然后它按预期工作了。
英文:
Thanks to this thread. As said there, I tried setting $GOPATH first and then referenced it in $PATH and also set $GOBIN. and implemented it all by sourcing ~/.bashrc.
Additionally, I changed my module name a bit and then built and installed it. And then it worked as expected.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论