【问题标题】:brew doctor Warning: How to add git to PATH?brew doctor 警告:如何将 git 添加到 PATH?
【发布时间】:2016-07-14 05:57:27
【问题描述】:

我在 OS X El Capitan 上安装了 Homebrew。在安装的最后步骤中,我应该使用

安装 git
brew install git

这很好。现在,如果我运行“brew doctor”,就会发生这种情况:

$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!

Warning: Git could not be found in your PATH.
Homebrew uses Git for several internal functions, and some formulae use Git
checkouts instead of stable tarballs. You may want to install Git:
  brew install git

如果我再次运行“brew install git”,我会得到:

$ brew install git 
Warning: git-2.7.4 already installed

所以不用说我的 git 版本是 2.7.4。 'brew update' 抛出:

$ brew update
Warning: git-2.7.4 already installed
Error: Git must be installed and in your PATH!

问题:如何修复我的 PATH,以便可以在我的 PATH 中找到 git,并且“brew doctor”会导致“您的系统已准备好进行 brew”?


附加信息:

  • which -a git 结果:

    $ which -a git
    /usr/local/bin/git
    /usr/local/bin/git
    /usr/bin/git
    
  • 我尝试了很多可能的修复,同时我执行了:

    echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile
    

    我的 ~/.bash_profile 现在看起来像这样:

    # Setting PATH for Python 2.7
    # The orginal version is saved in .bash_profile.pysave
    PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
    export PATH=/usr/local/bin:$PATH
    
  • 当我尝试安装木桶时:

    $ brew tap caskroom/cask
    ==> Installing git
    Warning: git-2.7.4 already installed
    Error: Git is unavailable
    
  • 酿造配置:

    $ brew config
    HOMEBREW_VERSION: 0.9.5
    ORIGIN: (none)
    HEAD: (none)
    Last commit: never
    HOMEBREW_PREFIX: /usr/local
    HOMEBREW_REPOSITORY: /usr/local
    HOMEBREW_CELLAR: /usr/local/Cellar
    HOMEBREW_BOTTLE_DOMAIN: https://homebrew.bintray.com
    CPU: quad-core 64-bit haswell
    OS X: 10.11.4-x86_64
    Xcode: 7.3
    CLT: 7.3.0.0.1.1457485338
    Clang: 7.3 build 703
    X11: N/A
    System Ruby: 2.0.0-p648
    Perl: /usr/bin/perl
    Python: /usr/local/bin/python => /usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/bin/python2.7
    Ruby: /usr/bin/ruby => /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
    Java: 1.8.0_40
    

编辑:向附加信息添加了木桶。

EDIT2:添加了 brew 配置并添加了 brew doctor 前缀

【问题讨论】:

  • 请同时发布brew doctorbrew config的完整输出。
  • @bfontaine 我添加了brew config 并完成了brew doctor(关于自制警告的一般说明,我一开始认为这并不重要)。
  • 谢谢; source ~/.bash_profile 能解决问题吗?
  • 很遗憾没有。我在 2 天前与 TheGeorgeous 的方法一起尝试过,但没有奏效。几秒钟前我也试过了,brew doctor 仍然提供相同的输出
  • brew info git 的输出是什么?

标签: git macos path homebrew


【解决方案1】:

这解决了我的问题:

cd /usr/local/Library/Homebrew
git pull origin master

然后我又跑了

brew update && brew upgrade

【讨论】:

  • 对于较新版本的 MacOS,请改用 cd /usr/local/Homebrew 路径
【解决方案2】:

对我来说,这是由于缺少 xcode 工具造成的,由 xcode-select --install 修复。

其他几个建议的修复,包括 brew 目录中的 git fetch 和/或更改 git core.autocrlf 并没有解决这个问题。

更详细地说,我从 brew brew uninstall --force git 中卸载了 git,但 Apple 自己的 git 然后没有工作(/usr/bin/git --version 报告 missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun)。

运行 brew doctor 建议运行 xcode-select --install,我运行了它,它修复了 Apple 的 git,也修复了 brew。 (然后可以通过 brew brew install git 重新安装 git。)

【讨论】:

  • 我刚刚更新到 macOS Mojave,我必须重新安装 Xcode 命令行工具才能让 brew(和 git)再次运行
  • 这行得通,对我来说就是答案。为什么“答案”是手动执行 git pull,而使用包管理器的全部本质不是手动执行任何操作,即使对于自制软件也是如此。啧啧
【解决方案3】:

简单运行:

export PATH=/usr/local/bin:$PATH

您的 PATH 变量应该类似于

PATH="/usr/bin:/usr/local/bin"

【讨论】:

  • 不幸的是没有工作;我运行了命令 export PATH=/usr/local/bin:$PATH 但这并没有改变我的 ~/.bash_profile 中的任何内容。之后,我手动将 ~/.bash_profile 更改为如下所示:PATH="/usr/bin:/usr/local/bin"export PATH=/usr/local/bin:$PATH 如果我完全误解了您的答案,请保持温和。我对 unix 终端没有太多经验
  • 你检查过你的.bashrc吗?您还必须运行 source .bashrc 来重新加载您的配置
  • 如果我运行source .bashrc它会显示No such file or directory。我只是关闭并重新打开终端以重新加载配置。据我所知,在这种情况下,我只需要查找 .bash_profile 并正确设置 PATH 以便 brew 找到 git?
【解决方案4】:

我找到了解决问题的方法。是/usr/local/Library/ENV/scm/git的文件格式错误造成的:

$ /usr/local/Library/ENV/scm/git --version
-bash: /usr/local/Library/ENV/scm/git: /bin/sh^M: bad interpreter: No such file or directory

所以我编辑了文件格式:

$ vi /usr/local/Library/ENV/scm/git

按'ESC',写:set fileformat=unix,按'Enter',写:wq!

这为我解决了问题。

【讨论】:

    【解决方案5】:

    如果您像我一样:使用 macOS El Capitan 并且没有 /usr/local/Library/ENV/scm/git,那么您可以这样做。

    cd /usr/local/
    # The folder where you've installed Homebrew
    git config --list --local
    

    寻找:core.autoxrlf=false

    如果没有看到它运行:git config --local core.autocrlf false

    然后运行:

    git fetch origin
    git reset --hard origin/master
    brew update
    

    【讨论】:

      【解决方案6】:

      我在跑brew update时遇到了同样的症状。

      在我的情况下,问题是由于设置了 GIT 的 bash 变量(到目录)。所以解决方案是为 brew 命令取消设置

      $ GIT= brew update
      

      【讨论】:

        【解决方案7】:

        与许多其他类似问题一样,libintl.8.dylib 可能存在问题:

        locate libintl.8.dylib
        

        如果 /gettext//libintl.*.dylib 存在

        brew link -f gettext
        

        转到(取决于版本)

        cd /usr/local/Homebrew 
        cd /usr/local/Library/Homebrew 
        

        并执行(确保您在 .../Homebrew 目录中)

        git pull origin master
        rm -fr ".git/rebase-apply"
        brew update && brew upgrade
        

        这最后需要一些时间,但之后一切正常。

        【讨论】:

          猜你喜欢
          • 2017-10-04
          • 1970-01-01
          • 1970-01-01
          • 2013-12-13
          • 1970-01-01
          • 2013-01-09
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多