如何使用当前的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
其他回答
更新:在Lion 10.7.4中,命令行工具已经在XCode中可用。你可以从App Store免费获得。
GCC for OSX不会编译从macports获得的一些包。 https://github.com/kennethreitz/osx-gcc-installer/downloads
除了从Apple安装命令行工具的“官方”版本,你也可以从这里安装Kenneth的版本:
https://github.com/kennethreitz/osx-gcc-installer
如果你所追求的只是命令行工具,它甚至不需要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.
如果你在尝试使用命令行工具时查看“控制台”,你会发现实际上有一个到Mountain Lion命令行工具的“非官方”链接!
所以试试吧:
http://adcdownload.apple.com/ios/ios_simulator__resigned/cltools_mountainliondp2_march12.dmg
这是我的控制台日志:
01/04/2012 15:41:54.258 Xcode: [MT] DVTDownloadable: Download failed. Downloadable: {
dependencies = (
);
fileSize = 141452226;
identifier = "Xcode.CLTools.10.8";
name = "Command Line Tools";
source = "http://adcdownload.apple.com/ios/ios_simulator__resigned/cltools_mountainliondp2_march12.dmg";
userInfo = {
ActivationPredicate = "$MAC_OS_X_VERSION >= '10.8.0' && $MAC_OS_X_VERSION < '10.9.0'";
InstallPrefix = "/";
InstalledIfAllSHA1SumsMatch = {
"/usr/bin/clang" = 600c35175775a6002452a88f17e00c570cd2e2d0;
};
Summary = "Before installing, note that from within Terminal you can use the XCRUN tool to launch compilers and other tools embedded within the Xcode application. Use the XCODE-SELECT tool to define which version of Xcode is active. Type \"man xcrun\" from within Terminal to find out more.\n\nDownloading this package will install copies of the core command line tools and system headers into system folders, including the LLVM compiler, linker, and build tools.";
"Xcode.SDKs" = (
);
};
version = "1.1.1";
}. Error: Error Domain=NSCocoaErrorDomain Code=3840 "The data couldn’t be read because it has been corrupted." (Encountered unknown ampersand-escape sequence at line 18) UserInfo=0x401bc8e60 {NSDebugDescription=Encountered unknown ampersand-escape sequence at line 18, kCFPropertyListOldStyleParsingError=The data couldn’t be read because it has been corrupted.}