按照官網(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
從報錯來看,是說 /Library/Developer/CommandLineTools 不是 xcode-select 的有效路徑
那么要做的就有兩件事:
1.找到 xcode-select的有效路徑
2.使用有效路徑替換 https://raw.githubusercontent.com/Homebrew/install/master/install 文件中的 /Library/Developer/CommandLineTools
1.查找 xcode-select的有效路徑
使用命令:xcode-select 查看其用法
userNameMacBook-Pro:test userName$ xcode-select
xcode-select: error: no command option given
Usage: xcode-select [options]
Print or change the path to the active developer directory. This directory
controls which tools are used for the Xcode command line tools (for example,
xcodebuild) as well as the BSD development commands (such as cc and make).
Options:
-h, --help print this help message and exit
-p, --print-path print the path of the active developer directory
-s <path>, --switch <path> set the path for the active developer directory
--install open a dialog for installation of the command line developer tools
-v, --version print the xcode-select version
-r, --reset reset to the default command line tools path
執行:xcode-select -p找到真正的路徑,輸出
/Applications/Xcode.app/Contents/Developer 即 xcode-select的有效路徑
2.使用有效路徑:/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)"即可