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

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

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

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


当前回答

“非官方”链接也可在

http://developer.apple.com/downloads/

403:禁止,除非使用合格的开发人员帐户登录。免费帐户可以访问除预发布软件和完整的操作系统安装之外的所有内容。特别是,与Xcode 4.4发布一致的命令行工具包(“2012年7月”软件包)在7月27日发布,用于Lion和Mountain Lion。

与日志文件、深度链接网页和Xcode首选项窗口不同,这个页面还链接到许多其他有用的下载,免费和付费开发者都可以下载,包括所有从Xcode中解绑定的东西(音频工具、辅助工具等)、OS X内核调试构建,以及Xcode 1.0版本的发布版本。

其他回答

我最近不得不通过SSH在Mountain Lion上安装Xcode命令行工具。 注意:我想这个过程对于任何版本的Xcode或OSX都是一样的。只要确保你的路径是正确的。 我是这样做的……

If you don't have a free Apple developer account, register for one Login to https://developer.apple.com/downloads Download the "Command Line Tools for Xcode" appropriate for your version of OSX For me, that was "Command Line Tools (OS X Mountain Lion) for Xcode - April 2014" Copy the dmg file to your remote In the following command, I'm using scp to securely copy the file from my local computer to the remote named remote $ scp ~/Downloads/command_line_tools_for_osx_mountain_lion_april_2014.dmg remote:Downloads/ ssh to your remote $ ssh remote mount the dmg file on the remote Here, I'm using hdiutil to mount the image $ hdiutil attach ~/Downloads/command_line_tools_for_osx_mountain_lion_april_2014.dmg install the package contained in the dmg Here, installer must be run with sudo because this package needs to be installed on the root file system $ cd /Volumes/Command\ Line\ Tools\ \(Mountain\ Lion\) $ sudo installer -pkg Command\ Line\ Tools\ \(Mountain\ Lion\).mpkg -target / unmount the dmg file $ hdiutil detach /Volumes/Command\ Line\ Tools\ \(Mountain\ Lion\) delete the dmg file from the remote; optional I see no purpose keeping it around, but you can if you want. $ rm ~/Downloads/command_line_tools_for_osx_mountain_lion_april_2014.dmg

如何获得安装在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. ...

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

Xcode 13 RC

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

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

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

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

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

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

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

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