在 OS X Mavericks 升级后,出现 git 错误 "unable to locate xcodebuild"。

64

当我尝试运行之前有效的git命令时,会出现以下信息:

dyld: Symbol not found: _sqlite3_intarray_bind
  Referenced from: /System/Library/Frameworks/CoreData.framework/Versions/A/CoreData
  Expected in: /opt/local/lib/libsqlite3.dylib
 in /System/Library/Frameworks/CoreData.framework/Versions/A/CoreData
git: error: unable to locate xcodebuild, please make sure the path to the Xcode folder is set correctly!
git: error: You can set the path to the Xcode folder using /usr/bin/xcode-select -switch

我该如何修复这个问题?

12个回答

163

这个对我有用 sudo xcode-select --switch /Library/Developer/CommandLineTools/


1
我曾经安装了Xcode和另一个Xcode beta版本。在卸载beta版本后,我遇到了“错误:执行失败:/usr/bin/otool -L /usr/bin/install_name_tool”的问题。然后我运行了这个命令,现在它又可以正常工作了。 - LetsGoRangers
1
我执行了 sudo xcode-select --switch /Applications/Xcode.app 但这并没有解决我的问题。为什么你的方法可以解决问题? - crisron
1
不知道你是怎么想到的,但这对我也起作用了。 - Edward Falk
12
对我来说不起作用。我收到了xcode-select: error: invalid developer directory '/Library/Developer/CommandLineTools/'的错误提示。 - Jason Liu
1
我也遇到了 xcode-select: error: invalid developer directory '/Library/Developer/CommandLineTools/' 的问题,对我来说解决办法就是从Appstore更新XCode应用程序。之后它开始正常工作了。 - lilline
显示剩余2条评论

43

经过大量的谷歌搜索和困惑,以下步骤可以解决问题(假设已安装Xcode)。有些步骤可能是可选的,请随意详细说明,因为我不是这些错误的专家。

  • 下载马瓦里克斯命令行工具 https://developer.apple.com/downloads/
  • xcode-select --install
  • sudo xcode-select -switch /Library/Developer/CommandLineTools
  • brew install sqlite3
  • 在我的.bashrc文件中注释掉DYLD_LIBRARY_PATH条目

你不需要下载Mavericks命令行工具/成为开发者。你可以从第二步开始。(假设你至少有新的Xcode) - Jono
在将命令行工具更新到OSX 10.9的版本6.0后,我在尝试安装redmine插件时遇到了OP的错误。关键是要运行命令“sudo xcode-select -switch /Library/Developer/CommandLineTools”,这解决了我的错误。谢谢! - Kirkland
个人而言,我只需要步骤1-3。感谢这些信息! - gdibble
我只需要第三步。 - MikeF
我已经升级到Big Sur 11.6.3,并遇到了与原帖相同的问题。通过执行步骤2和3,我的问题得到了解决,就像其他几个人在这里做的一样。我最初只执行了步骤3,这导致错误提示步骤2中给定的路径不是允许的路径。希望这能帮助一些遇到类似但不完全相同问题的人。 - S.Jamal
显示剩余3条评论

32

在 MacOS Mojave 上,这对我有用(git 2.21.0):

xcode-select --install
sudo xcode-select -switch /Library/Developer/CommandLineTools

谢谢!在Catalina上也可以工作。这是一个更好的答案,因为需要安装(第一个命令)。 - Sarang

14
如果您已经安装了Xcode,您可以运行以下命令来确定和指向正确的位置。

如果你已经安装了Xcode,你可以运行下面的命令来确定并指向正确的位置

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

或者使用 AppStore 安装最新的 Xcode。


在我升级到Catalina之后,我的git无法工作。在应用商店中更新Xcode对我有帮助。我不需要切换任何东西。 - Zufeng

12
xcode-select --install
sudo xcode-select -switch /Library/Developer/CommandLineTools

这对我有效。


9
很可能您需要重新安装命令行工具,然后将xcode路径指向该位置。
首先安装工具。 $ xcode-select --install
这将把工具安装到文件夹 /Library/Developer/CommandLineTools 中。
然后像这样指向xcode路径到工具安装的位置: $ sudo xcode-select -switch /Library/Developer/CommandLineTools
注意:您可以通过命令 $ xcode-select -p 查看当前的xcode路径。当我遇到错误时,我的初始路径是指向 /Applications/Xcode.app/Contents/Developer。

8

这个方法在我的MacOS High Sierra(10.13.6)上有效

使用以下命令:

sudo xcode-select --switch /Library/Developer/CommandLineTools/


3

当我执行命令 'git clone xxx' 时,出现了以下错误:

dyld: Library not loaded: @rpath/libswiftCore.dylib Referenced from: /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild Reason: image not found git: error: unable to locate xcodebuild, please make sure the path to the Xcode folder is set correctly! git: error: You can set the path to the Xcode folder using /usr/bin/xcode-select -switch

然后,执行以下命令:

xcode-select -p

指向 /Applications/Xcode.app/Contents/Developer

运行以下命令后, sudo xcode-select -switch /Library/Developer/CommandLineTools

它将指向 /Library/Developer/CommandLineTools


2

我在一台全新的High Sierra系统上运行Fastlane时遇到了同样的问题。

解决方法如下:

sudo xcode-select --switch /Applications/Xcode.app

0

或许您应该安装适用于Mavericks的Xcode 5.0.1版本。请检查更新。


1
问题在我的电脑上也是完全相同的配置发生了。 - Philip

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接