Mat*_*one 17 path git homebrew osx-mavericks macos
当我尝试使用刚刚通过自制软件安装的最新版本的 git 时,我遇到了一个非常奇怪的问题。which git
将我指向自制软件安装,但调用git
返回与 OS X 一起安装的原始版本。
我首先检查以查看我使用的原始版本。
[user@home ~]$ git --version
git version 1.8.5.2 (Apple Git-48)
Run Code Online (Sandbox Code Playgroud)
然后我去自制软件安装最新版本。
[user@home ~]$ brew install git
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/git-2.0.0.mavericks.bottle.2.tar.gz
######################################################################## 100.0%
==> Pouring git-2.0.0.mavericks.bottle.2.tar.gz
==> Caveats
The OS X keychain credential helper has been installed to:
/usr/local/bin/git-credential-osxkeychain
The 'contrib' directory has been installed to:
/usr/local/share/git-core/contrib
Bash completion has been installed to:
/usr/local/etc/bash_completion.d
zsh completion has been installed to:
/usr/local/share/zsh/site-functions
==> Summary
/usr/local/Cellar/git/2.0.0: 1324 files, 31M
Run Code Online (Sandbox Code Playgroud)
看起来它奏效了!检查它是否指向正确的 git
[user@home ~]$ which git
/usr/local/bin/git
Run Code Online (Sandbox Code Playgroud)
应该不错吧?没那么快
[user@home ~]$ git --version
git version 1.8.5.2 (Apple Git-48)
Run Code Online (Sandbox Code Playgroud)
这很奇怪。我真的指向正确的 git 吗?
[user@home ~]$ ls -l /usr/local/bin/git
lrwxr-xr-x 1 user group 27 Jul 3 15:54 /usr/local/bin/git -> ../Cellar/git/2.0.0/bin/git
Run Code Online (Sandbox Code Playgroud)
当然看起来像。当我手动调用它时有效
[user@home ~]$ /usr/local/Cellar/git/2.0.0/bin/git --version
git version 2.0.0
Run Code Online (Sandbox Code Playgroud)
但不像 git
[user@home ~]$ which git
/usr/local/bin/git
[user@home ~]$ git --version
git version 1.8.5.2 (Apple Git-48)
Run Code Online (Sandbox Code Playgroud)
关于可能导致这种情况的任何想法?
编辑:解决了。source .bashrc
修复。仍然很好奇为什么which
会返回正确的可执行文件,但它不会被调用,如果有人可以解释的话。
rea*_*eek 26
Shell 维护在$PATH
变量中找到可执行文件的路径的缓存。所以它缓存/usr/bin/git
而不是/usr/local/bin/git
,因为当你的 shell 启动时后者不存在。hash -r
从当前终端在 Bash 中运行将清除此缓存,然后在其中找到的第一个实例$PATH
应该是执行的实例。
小智 5
我遇到了完全相同的问题。这是我的解决方案。
brew uninstall git
# make sure everything is alright, maybe brew will give you some hint
brew doctor
brew update
brew install git
# magic happen, brew will give you hint /usr/bin occurs before /usr/local/bin
# and recommend you run following command
brew doctor
echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile
Run Code Online (Sandbox Code Playgroud)
之后你就完成了,但是当你运行时你看不到任何变化git --version
。只需注销并重新登录,git --version
再次运行。
归档时间: |
|
查看次数: |
13472 次 |
最近记录: |