You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac Monterey系统下用Brew安装PHP@7.4遇Git路径错误求助

解决brew安装PHP@7.4时的Git路径与Ruby版本错误

问题说明

在Mac Monterey系统执行brew install php@7.4时,出现两类错误:

  1. Error: Git must be installed and in your PATH!
  2. Ruby类型错误:Version value must be a string; got a NilClass ()

已尝试brew doctor和brew upgrade,问题未解决。

解决步骤

步骤1:确认Git安装并配置系统PATH

  • 检查Git是否安装:执行以下命令,若提示“command not found”则需安装
    git --version
    
  • 安装Git(通过Xcode命令行工具):
    xcode-select --install
    
  • 将Git路径加入系统PATH:
    编辑你的Shell配置文件(如~/.zshrc或~/.bash_profile,根据使用的Shell选择),添加以下内容:
    export PATH="/usr/local/bin:/usr/bin:$PATH"
    
    保存后执行source ~/.zshrc(对应你的配置文件)使修改生效。

步骤2:修复Homebrew系统版本检测问题

手动指定Mac系统版本环境变量,解决Ruby的NilClass错误:

export MACOSX_DEPLOYMENT_TARGET=12.0

执行后再次尝试安装PHP@7.4:

brew install php@7.4

步骤3:重置Homebrew核心文件(若前两步无效)

重置Homebrew核心组件,修复可能的文件损坏:

cd /usr/local/Homebrew
git fetch --force
git reset --hard origin/master
brew cleanup
brew update

完成后重新执行安装命令。


内容的提问来源于stack exchange,提问作者Andrew

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.25 10:54:37