如何使用当前的Xcode/Mac OS X v10.8 (Mountain Lion)或更高版本安装命令行构建工具?

与Xcode不同,它没有安装程序,只是一个包。

看起来所有的命令行工具都在包中,在Contents/Developer下面,但是没有设置适当的环境变量来使用它们。

是否有一个脚本,我可以运行,将设置我的环境,以支持从命令行构建?


当前回答

更新:在Lion 10.7.4中,命令行工具已经在XCode中可用。你可以从App Store免费获得。

GCC for OSX不会编译从macports获得的一些包。 https://github.com/kennethreitz/osx-gcc-installer/downloads

其他回答

至于大sur..

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install

感谢自制啤酒维护者把这有用的消息在酿造医生

通过将我的Mac更新到最新的Mac OS(即Big Sur),一切都分解为重复要求安装Xcode-select。

这可能看起来很奇怪,但我通过重新安装并更新到最新的Xcode解决了这个问题。

这只是我解决问题的经验。

如何获得安装在Xcode 4.4 / Mac OS X v10.8 (Mountain Lion)或更高版本的命令行构建工具?

对于OS X 10.9,你只需安装Xcode。命令行工具与Xcode捆绑在一起。技术说明TN2339,从命令行构建Xcode常见问题解答:

在OS X 10.9版本的Xcode中,无法下载命令行工具。如何在我的机器上安装它们?

In OS X 10.9, the Downloads pane of Xcode Preferences does not support downloading command-line tools. Use any of the following methods to install command-line tools on your system: If Xcode is installed on your machine, then there is no need to install them. Xcode comes bundled with all your command-line tools. OS X 10.9 includes shims or wrapper executables. These shims, installed in /usr/bin, can map any tool included in /usr/bin to the corresponding one inside Xcode. xcrun is one of such shims, which allows you to find or run any tool inside Xcode from the command line. Use it to invoke any tool within Xcode from the command line. ...

Xcode命令行工具可以从这里下载:https://developer.apple.com/downloads/index.action#

2014年4月版直接下载链接(适合想马上上手的开发人员) https://developer.apple.com/downloads/download.action?path=Developer_Tools/command_line_tools_os_x_mavericks_for_xcode__april_2014/command_line_tools_for_osx_mavericks_april_2014.dmg

如果你想使用XCode本身提供的工具版本,你可以使用xcrun(例如xcrun git)。从下载首选项窗格底部的帮助:

注意,您可以在终端中使用XCRUN工具来启动 编译器和其他嵌入在Xcode应用程序中的工具。使用 Xcode - select工具定义激活的Xcode版本。 在终端内输入“man xcrun”以了解更多信息。