duanluangua8850 2019-02-20 23:24
浏览 102
已采纳

如何为所有用户安装golang二进制文件

From all of the Golang tutorials I have read, the way that you install a Go program is by setting the environment variable GOPATH=~/go or something similar, and then you can run go get blah and Go will download the program and put the binary in ~/go/bin. You also have to add ~/go/bin into your $PATH environment variable so that you can run the programs.

How would you go about installing a Golang program into a common location for all users, so that each user on a system did not need to add a PATH environment variable?

The only way I can see of doing it is to make a directory like /usr/local/go, and set that as my GOPATH when I install the program, and then I need to add /usr/local/go/bin into the system-wide $PATH so that all users can run the programs. Is that how it should be done?

  • 写回答

2条回答 默认 最新

  • dongluan2612 2019-02-21 01:42
    关注

    There are more environment variables that control how go ... commands work. See: https://golang.org/cmd/go/#hdr-Environment_variables. In this case, you can set GOBIN to your desired install location. Ex:

    GOBIN=/path/to/common/binaries go get blah
    

    will put the blah binary in /path/to/common/binaries. Note that you'll likely have to run with sudo.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵