Mac 使用

安装 homobrew

Posted by JH on May 31, 2021

Mac 安装 homobrew 报错解决

按照官网(https://brew.sh/index_zh-cn.html)给的命令:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

执行后 报错:

xcode-select: error: invalid developer directory ‘/Library/Developer/CommandLineTools’ Failed during: /usr/bin/sudo /usr/bin/xcode-select –switch /Library/Developer/CommandLineTools

可以查找 xcode-select的有效路径

  1. xcode-select -p找到真正的路径

如果能找到正确的路径,如 /Applications/Xcode.app/Contents/Developer

  1. 使用有效路径:/Applications/Xcode.app/Contents/Developer 替换 https://raw.githubusercontent.com/Homebrew/install/master/install 文件中的 /Library/Developer/CommandLineTools

    将https://raw.githubusercontent.com/Homebrew/install/master/install 内容复制下来,将第306和315行两处的/Library/Developer/CommandLineTools 改为/Applications/Xcode.app/Contents/Developer 并保存名为 install的文件

3.进入保存的install文件目录下,执行 ruby -e “$(cat install)”即可

不可正常查找 xcode-select的有效路径

使用 xcodebuild,如果显示 xcode-select: note: no developer tools were found at '/Applications/Xcode.app', requesting install. Choose an option in the dialog to download the command line developer tools. 表明没有安装 xcode,此时使用 xcode-select --install安装,可能显示网络问题建议使用下述步骤安装:

  1. App Store 搜索 Xcode 并安装,查看版本号

  2. 进入apple developer下载页面,登陆你的Apple账户 https://developer.apple.com/download/more/ 搜索关键字 Command Line Tools,选择你当前macOS系统版本下所使用的对应版本Xcode

  3. 下载后安装即可

这样就可以解决homebrew关于 xcode-select –install 无法下载安装这个问题了