doudi8298 2016-04-15 14:35
浏览 135
已采纳

相当于npm install -g的Golang

If I had a compiled Golang program that I wanted to install such that I could run it with a bash command from anywhere on my computer, how would I do that? For example, in nodejs

npm install -g express

Installs express such that I can run the command

express myapp

and express will generate a file directory for a node application called "myapp" in whatever my current directory is. Is there an equivalent command for go? I believe now with the "go install" command you have to be in the directory that contains the executable in order to run it

Thanks in advance!

  • 写回答

4条回答 默认 最新

  • duan5362 2016-04-15 14:42
    关注

    As far as I know, there is no direct equivalent to npm install -g. The closest equivalent would not be go install, but go get. From the help page (go help get):

    usage: go get [-d] [-f] [-fix] [-insecure] [-t] [-u] [build flags] [packages]

    Get downloads and installs the packages named by the import paths, along with their dependencies.

    By default, go get installs binaries to $GOPATH/bin, so the easiest way to make those binaries callable from everywhere is to add that directory to your $PATH.

    For this, put the following line into your .bashrc (or .zshrc, depending on which shell you're using):

    export PATH="$PATH:$GOPATH/bin"
    

    Alternatively, you could also copy or link the executables to /usr/local/bin:

    ln -s $GOPATH/bin/some-binary /usr/local/bin/some-binary
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊