去安装有什么用? [英] What does go install do?

查看:62
本文介绍了去安装有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档没有提及 build install 的作用

我的期望是,就像 make install 一样;即它将已编译的内容放入最终位置(/usr/local/bin/my_new_toy 或其他内容),但似乎将其放入 GOROOT/bin

My expectation was that it's like make install; i.e. it takes the compiled stuff and puts in its final location (/usr/local/bin/my_new_toy or whatever) but it seems that it puts things in GOROOT/bin

我可以告诉我去做一个 make install -即把东西放到其他地方吗?还是我只写一个makefile(请告诉我不)?

Can I tell go to do a make install - i.e. put things elsewhere? Or do I just write a makefile (please tell me no)?

推荐答案

如果要将二进制文件转到特定位置,则可以使用环境变量 GOBIN :

If you want binary files to go to a specific location, you can use the environment variable GOBIN :

bin/目录包含已编译的命令.每个命令都以以下名称命名它的源目录,但只有最后一个元素,而不是整个路径.也就是说,将源代码位于DIR/src/foo/quux的命令安装到DIR/bin/quux,而不是DIR/bin/foo/quux.foo/被剥离,以便您可以将DIR/bin添加到您的PATH中以获取已安装的命令.如果设置了GOBIN环境变量,将命令安装到目录而不是DIR/bin.

来源: http://golang.org/cmd/go/#hdr-GOPATH_environment_variable

GOBIN=/usr/local/bin/ go install

如果要每个项目的 bin/目录,则可以简单地将项目路径附加到 GOPATH ,但是您的代码必须位于 $ project-path/src/ go install 将所有二进制文件放入 $ project-path/bin .

If you want per-project bin/ directory then you can simply append your project path to GOPATH, however you must have your code under $project-path/src/ and go install will put all the binaries in $project-path/bin.

export GOPATH=/dir1:/dir2:/dir3

如果未设置GOBIN,则来自/dir1/src的二进制文件将以/dir1/bin结尾,来自/dir2/src的二进制文件最终位于/dir2/bin中,依此类推(以及二进制文件$ GOROOT/src中的文件最终以$ GOROOT/bin中的文件结尾.

If GOBIN is not set, binaries from /dir1/src end up in /dir1/bin, binaries from /dir2/src end up in /dir2/bin, and so on (and binaries from $GOROOT/src end up in $GOROOT/bin).

来源: https://groups.google.com/forum/#!topic/golang-nuts/-mN8R_Fx-7M

您还可以使用(感谢JimB):

And you can also just use (thanks JimB):

go build -o /path/binary-name

这篇关于去安装有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆