Xcode - install Command Line Tools

2018-12-31 05:05发布

How do I get the command line builds tools installed with current Xcode / Mac OS X v10.8 (Mountain Lion) or later?

Unlike Xcode there is no installer (it's just a bundle).

It looks like all the command line tools are there (in the bundle, under Contents/Developer), but none of the appropriate environment variables set to use them.

Is there a script somewhere I can run that will setup my environment to support building from the command line?

12条回答
情到深处是孤独
2楼-- · 2018-12-31 05:41

Instead of installing the "official" build of the command line tools from Apple, you can also install Kenneth's build from here:

https://github.com/kennethreitz/osx-gcc-installer

It doesn't even require XCode if all you are after is the command line tools.

查看更多
春风洒进眼中
3楼-- · 2018-12-31 05:41
笑指拈花
4楼-- · 2018-12-31 05:43

If you want to use the version of tools provided in XCode itself you can use xcrun (e.g. xcrun git). From the help at the bottom of the download preference pane:

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.

查看更多
伤终究还是伤i
5楼-- · 2018-12-31 05:45

Xcode 5.1 and OSX 10.9. (also works with Xcode 5.1.1 + OSX 10.10)

xcode-select --install worked with version 2333, failed with version 2003. So, try xcode-select --install and if that does not work download as described below.

In early February 2014 xcode-select --install has been reporting that "Can't install the software because it is not currently available from the Software Update server". In late February 2014 the command started only displaying help. The solution is to download directly, see "Separate Download" below.

Xcode 5.0.1 and OSX 10.9

With Xcode 5.0.1 and Mavericks 10.9 the command line tool is no longer available through Xcode. Instead they must be downloaded from the Apple Developer Tools site: https://developer.apple.com/downloads/index.action. This requires signing in with a developer account.

Or via terminal (from the release docs): The Command Line Developer Tools package can be installed on demand using "xcode-select --install” and the installed tools will be automatically updated using Software Update. OS X 10.9 is required for this feature. For earlier versions, continue to use the in-app download in Xcode.

Running the command in terminal produces the following GUI:enter image description here

Inside Xcode (5.0)

Xcode includes a new "Downloads" preference pane to install optional components such as command line tools, and previous iOS Simulators. To open this pane click the "Xcode" button in the top left of the screen near the Apple logo, then click "Preferences", then click "Downloads".

Xcode 5.0 screenshot: enter image description here

Xcode 4.x screenshot: screenshot of downloads pane

Separate Download

If you do not have Xcode, they are available as a separate download from Apple:

Go to developer.apple.com/downloads/index.action, and sign in with your Apple ID (the download's free). In the pane on the left, search for "command line tools" and choose the package appropriate to your version of OS X. Requires Mac OS X 10.7.3 or later.

查看更多
几人难应
6楼-- · 2018-12-31 05:47

I recently had to install Xcode command line tools on Mountain Lion over SSH.

Notice: I imagine this process would work identically for any version of Xcode or OSX. Just make sure you get your paths correct.

Here's how I did it...

  1. If you don't have a free Apple developer account, register for one

  2. Login to https://developer.apple.com/downloads

  3. 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"

  4. 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/
    
  5. ssh to your remote

    $ ssh remote
    
  6. 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
    
  7. 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 /
    
  8. unmount the dmg file

    $ hdiutil detach /Volumes/Command\ Line\ Tools\ \(Mountain\ Lion\)
    
  9. 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
    
查看更多
牵手、夕阳
7楼-- · 2018-12-31 05:49

UPDATED: On Lion 10.7.4 the Command Line Tools are already available from withing XCode. You can get it freely from App Store.

The GCC for OSX won't compile some packages obtained from macports. https://github.com/kennethreitz/osx-gcc-installer/downloads

查看更多
登录 后发表回答