0x01 前言

从macOS Sierra Public Beta开放开始我就更新了macOS Sierra。更新后当我使用brew安装python模块时却出现xcrun错误,因此开始我的修复之旅。

0x02 尝试修复

我尝试升级我的brew:

MacBook-Air:~ terence$ brew update
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
Error: /usr/local is not writable. You should change the ownership
and permissions of /usr/local back to your user account:
  sudo chown -R $(whoami) /usr/local

抛出错误:

Error: /usr/local is not writable. You should change the ownership

抛出的错误中的最后一行给出了解决方法:

sudo chown -R $(whoami) /usr/local

当尝试使用上面的命令修复目录权限时:

MacBook-Air:~ terence$ sudo chown -R $(whoami) /usr/local
Password:
MacBook-Air:~ terence$ brew update
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
Error: The following formula:
  git
cannot be installed as a binary package and must be built from source.
Install the Command Line Tools:
  xcode-select --install

Error: Git must be installed and in your PATH!

从上面抛出的错误中看到了问题点:找不到git,因为Command Line Tool还没安装。通过下面命令进行安装:

xcode-select --install

WechatIMG4

安装完成后再次尝试修复文件夹权限:

sudo chown -R $(whoami) /usr/local

0x03 升级

升级brew:

MacBook-Air:~ terence$ brew update
Already up-to-date.

0x04 结语

问题不大,我写这篇文章的时候brew尚未支持此版本的macOS