douzhun4124 2014-06-05 20:27
浏览 55
已采纳

去安装做什么?

The docs say nothing about what build vs install does

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

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)?

  • 写回答

2条回答 默认 最新

  • dongnao9525 2014-06-05 20:51
    关注

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

    The bin/ directory holds compiled commands. Each command is named for its source directory, but only the final element, not the entire path. That is, the command with source in DIR/src/foo/quux is installed into DIR/bin/quux, not DIR/bin/foo/quux. The foo/ is stripped so that you can add DIR/bin to your PATH to get at the installed commands. If the GOBIN environment variable is set, commands are installed to the directory it names instead of DIR/bin.

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

    GOBIN=/usr/local/bin/ go install
    

    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
    

    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).

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

    And you can also just use (thanks JimB):

    go build -o /path/binary-name
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退