如何使用当前的Xcode/Mac OS X v10.8 (Mountain Lion)或更高版本安装命令行构建工具?
与Xcode不同,它没有安装程序,只是一个包。
看起来所有的命令行工具都在包中,在Contents/Developer下面,但是没有设置适当的环境变量来使用它们。
是否有一个脚本,我可以运行,将设置我的环境,以支持从命令行构建?
如何使用当前的Xcode/Mac OS X v10.8 (Mountain Lion)或更高版本安装命令行构建工具?
与Xcode不同,它没有安装程序,只是一个包。
看起来所有的命令行工具都在包中,在Contents/Developer下面,但是没有设置适当的环境变量来使用它们。
是否有一个脚本,我可以运行,将设置我的环境,以支持从命令行构建?
当前回答
我最近不得不通过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 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.
去developer.apple.com/download/all/(如果你没有登录请登录) 展开所需版本的“命令行工具”的“查看详细信息”工具提示 下载这些命令行工具的.dmg文件 下载.dmg文件后,双击它并安装它
除了从Apple安装命令行工具的“官方”版本,你也可以从这里安装Kenneth的版本:
https://github.com/kennethreitz/osx-gcc-installer
如果你所追求的只是命令行工具,它甚至不需要XCode。
至于大sur..
sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install
感谢自制啤酒维护者把这有用的消息在酿造医生
Xcode 5.1和OSX 10.9。(也适用于Xcode 5.1.1 + OSX 10.10)
Xcode-select——install适用于2333版本,不适用于2003版本。所以,尝试xcode-select——install,如果不工作,下载如下所述。
在2014年2月初xcode-select -install一直报告“无法安装软件,因为它目前不可从软件更新服务器”。2014年2月底,该命令开始只显示帮助。解决方法是直接下载,参见下面的“单独下载”。
Xcode 5.0.1和OSX 10.9
在Xcode 5.0.1和Mavericks 10.9中,命令行工具不再可以通过Xcode使用。相反,它们必须从苹果开发者工具网站https://developer.apple.com/downloads/index.action下载。这需要使用开发人员帐户登录。
或者通过终端(来自发布文档):命令行开发人员工具包可以按需使用“xcode-select——install”安装,安装的工具将使用软件更新自动更新。此特性需要OS X 10.9。对于早期版本,继续在Xcode中使用应用内下载。
在terminal中执行该命令会生成如下图形界面:
内部Xcode (5.0)
Xcode包含一个新的“下载”首选项窗格,用于安装可选组件,如命令行工具和以前的iOS模拟器。要打开这个面板,点击屏幕左上方苹果logo附近的“Xcode”按钮,然后点击“首选项”,然后点击“下载”。
Xcode 5.0截图:
Xcode 4。x截图:
单独下载
如果你没有Xcode,你可以从苹果单独下载:
登陆developer.apple.com/downloads/index.action,用你的苹果账号登录(下载是免费的)。在左侧窗格中,搜索“命令行工具”,并选择适合您的OS X版本的软件包。