`go get` 命令在 `$PATH` 中存在多个 git 版本时,会使用哪个 git 版本?

huangapple go评论74阅读模式
英文:

Which git version does 'go get' use when multiple git are available in $PATH?

问题

我安装了一个位于/usr/bin/git的系统版本和一个位于~/bin/git的本地版本。两者都在$PATH中。

  • go get ...会使用哪个git?我假设它会使用在$PATH中找到的第一个git,通常是/usr/bin/git
  • 有没有办法强制go get ...使用不同路径下的git二进制文件,而不是找到的第一个?例如~/bin/git/some/other/path/to/git
英文:

I have a system installed /usr/bin/git and a local ~/bin/git. Both are in $PATH.

  • Which git will go get ... use? I'm assuming the first one it can find in $PATH, which usually would be /usr/bin/git.
  • Is there a way to force go get ... to use a git binary from a different path and not the first one it can find? e.g. ~/bin/git or /some/other/path/to/git.

答案1

得分: 2

为了在设置的路径环境中创建一个别名,你可以按照你的需求进行设置。

然后它将在该环境中运行,并且不会受到你当前环境的影响。

正如你所述,你创建了一个类似这样的别名:

alias go="env GOROOT=$HOME/go GOPATH=$HOME/gocode GOBIN=$HOME/gocode/bin PATH=$HOME/go/bin:$HOME/bin:$GOBIN:$PATH $HOME/go/bin/go"
英文:

Create an alias for go where you set the path environment like you want.

Then it will run in that environment, and won't be concerned with your environment.

As you stated, you created an alias like this:

alias go="env GOROOT=$HOME/go GOPATH=$HOME/gocode GOBIN=$HOME/gocode/bin PATH=$HOME/go/bin:$HOME/bin:$GOBIN:$PATH $HOME/go/bin/go"

huangapple
  • 本文由 发表于 2014年10月30日 05:55:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/26641343.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定