更改 git 在 linux 上的安装位置

Changing the location of git installation on linux

如果这看起来很基础,我深表歉意,但我是 linux 的新手,不太确定如何继续。我当前的 git 版本是 1.7.1,位于 /usr/bin/git,但更新版本的 git (1.8) 现在可以在 /usr/src/git/bin/git 中使用。如何让 git 默认使用此版本而不是 1.7.1 版本?

您必须确保调用正确的可执行文件。这可以通过显式调用 /usr/src/git/bin/git 而不是 git 来完成。当然,一直打字会很烦人,因此您可以通过添加行

使 git 成为该路径的别名
alias git=/usr/src/git/bin/git

到您的 .bashrc,或通过添加行

将目录 /usr/src/git/bin 添加到您的二进制搜索路径
export PATH="/usr/src/git/bin:$PATH"

要测试其他 git 安装是否在正确的位置搜索核心二进制文件,您可以检查 git --exec-path.

的输出