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

Apple M1(Sonoma 14.2.1)安装Homebrew失败求助

问题描述

我想安装Git,根据Git官方说明,Homebrew是安装Git的前置条件。

  • 设备:Apple M1
  • macOS版本:Sonoma 14.2.1
  • Xcode版本:15.2(从苹果开发者官网下载)

我用以下bash命令安装Homebrew:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

执行过程中出现如下错误:

xcrun: error: unable to load libxcrun (dlopen(/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib, 0x0005): tried: '/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need '')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib' (no such file), '/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need ''))).
Failed during: /usr/bin/git -c init.defaultBranch=master init --quiet

我看不懂这个错误,Git官网说苹果随Xcode附带Git二进制包,请问这和Homebrew安装失败有关吗?盼解决。


解决方案

错误原因

这个错误是因为你的Command Line Tools(CLT)是x86_64架构版本,和M1的arm64架构不兼容,导致xcrun无法加载对应的库文件,进而中断了Homebrew的安装流程。Xcode自带的Git和这个问题无关——Homebrew安装时调用的是系统级的Git,CLT架构不匹配才是核心问题。

修复步骤

  1. 卸载现有x86版本的Command Line Tools
    打开终端执行:

    sudo rm -rf /Library/Developer/CommandLineTools
    
  2. 安装适配arm64的Command Line Tools
    终端运行:

    xcode-select --install
    

    按照弹窗提示完成安装,确保下载的是适配M1芯片的arm64版本。

  3. 验证CLT架构与配置
    先确认Xcode的CLT路径正确:

    sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
    

    再检查架构是否匹配:

    lipo -info /Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib
    

    输出应包含arm64字样。

  4. 重新安装Homebrew
    再次运行初始安装命令即可:

    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    

关于Xcode自带Git的说明

Xcode确实自带Git,路径为/Applications/Xcode.app/Contents/Developer/usr/bin/git,如果只是需要使用Git,无需通过Homebrew安装,直接将该路径添加到环境变量PATH中即可使用。但如果需要通过Homebrew管理Git或其他软件,必须先解决CLT的架构问题才能正常安装Homebrew。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.01 21:23:14