如何使用当前的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

其他回答

去developer.apple.com/download/all/(如果你没有登录请登录) 展开所需版本的“命令行工具”的“查看详细信息”工具提示 下载这些命令行工具的.dmg文件 下载.dmg文件后,双击它并安装它

以下是苹果开发者服务器上的命令行工具链接。你可能需要一个苹果开发者(付费/高级)帐户才能访问它们。你可以下载当前的(稳定版和beta版)Xcode工具。(不需要设备验证。在选择命令行工具时,只需确保您的macOS和XCode工具/SDK版本)

Xcode 13 RC

Xcode 13 RC (命令行工具(Xcode 13 RC) - macOS BigSur +)

一旦你在系统中安装了最新的命令行工具,从Xcode菜单中设置它。

▶位置▶命令行工具▶选择合适的命令行工具

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 Command Line Tools can be installed as a side effect of running git --version in Terminal without Git installed. You will be prompted to install the tools as a requirement for running Git. Apple ships a binary of git with the Command Line tools. This is confirmed on the Git for Mac Download page. This seems like a valid option considering that Homebrew requires the Command Line tools to install Git as well according to another SO post. Otherwise, the previous answers are the most direct methods of install the tools.

您可以在bash中自动安装命令行工具。在自动化开发人员入职设置过程时,我需要这样做。

xcode-select --install && sleep 1
osascript -e 'tell application "System Events"' -e 'tell process "Install Command Line Developer Tools"' -e 'keystroke return' -e 'click button "Agree" of window "License Agreement"' -e 'end tell' -e 'end tell'