556

How do I get the command-line build tools installed with the 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 in the bundle, under Contents/Developer, but none of the appropriate environment variables are set to use them.

Is there a script I can run that will set-up my environment to support building from the command line?

6
  • 1
    see stackoverflow.com/questions/9326647/…
    – fredley
    Commented Feb 17, 2012 at 14:16
  • 1
    For XCODE 5.1 and up: note that you can no longer install from within XCODE any longer. @Zaph notes this below but the fastest way is the terminal command $ xcode-select --install
    – AndyBean
    Commented Apr 11, 2014 at 20:04
  • @AndyBean "xcode-select --install" does not always work, the issue is that there is a problem in the OSX update that is not updating "xcode-select". Version 2333 works, version 2003 fails, I have the second on most of my Macs. This explains why it works for some and not all.
    – zaph
    Commented Apr 11, 2014 at 22:09
  • 2
    @Zaph and others - ran into version issue. ran sudo xcode-select --reset, and then reinstalled. then ran software update, then all fixed.
    – azochz
    Commented Apr 6, 2015 at 17:16
  • 1
    simply use the downloads tab in the Xcode preferences dialog.
    – Mor4eza
    Commented Jun 28, 2022 at 12:57

16 Answers 16

835

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.

18
  • 41
    works like a charm! Ridiculous that the command line tools are not installed by default!
    – Tilo
    Commented Aug 20, 2012 at 22:28
  • 5
    Just to add sth here: once registered, go to developer.apple.com/xcode -> click on "View downloads" and find the Command line tools in the list - hope this saves some time for someone.
    – pagid
    Commented Nov 21, 2012 at 0:37
  • 177
    I guess I'm only allowed to speak for myself, but from a person coming over from a sane Unix distro, the idea that your main system compiler is installed this way is pure madness.
    – Mark Grey
    Commented Mar 19, 2013 at 18:33
  • 5
    Is this true? Updating Xcode through the AppStore seems to install command line tools as well. Also: it's unclear from the above whether one should expect to see the tools in the 5.0.1/10.9 Downloads preference pane (and if so whether the absence means they're already installed).
    – orome
    Commented Oct 27, 2013 at 20:12
  • 6
    If you're using OS X 10.9 and have run "xcode-select --install" you can follow that with "softwareupdate -l" which will show you what is about to be installed and "sudo softwareupdate -i -a" to go ahead and install what you have selected. Commented Jan 26, 2014 at 19:14
41

Here are links for Command Line Tools, located at Apple Developer Server. You may need an apple developer (Paid/Premium) account to access them. You can download current (stable and beta) Xcode Tools. (It does not need device verification. Just ensure your macOS and XCode Tool/SDK version while choosing your command line tool)

Xcode 13 RC

Once you've latest command line tool installed in your system, set it from Xcode Menu.

(Xcode Menu Items) Xcode ▶ Preferences ▶ Location ▶ Command Line Tool ▶ Select appropriate command line tool

enter image description here

2
  • This answer worked for me pointing to 12.0.1 > I got an error trying to rebuild a package in Atom (text editor) saying there were no command line tools. I launched Xcode prefs and the command line tools selector was blank! I set the selector to 12.0.1, switched back to Atom, and tried rebuilding the package and it worked.
    – August
    Commented Oct 14, 2020 at 18:17
  • Link's dead....
    – user3064538
    Commented Oct 29, 2022 at 5:59
40

If you take a look into "Console" while trying to pull the Command Line Tools, you will find out that there is actually an "unofficial" link to the Mountain Lion Command Line Tools!

So just try:

http://adcdownload.apple.com/ios/ios_simulator__resigned/cltools_mountainliondp2_march12.dmg

Here is my Console log:

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.}
5
  • 1
    You can also login at developer.apple.com (fee account is fine) and download it there. I was the only way for me. Commented Jul 25, 2012 at 22:00
  • I wasnt able to download neither through developer.apple.com, neither XCode. This worked perfectly. Thanks!! Commented Jul 25, 2012 at 23:44
  • 9
    The usefulness of the link seems to have expired: Your session has expired. Please return to the ADC Member Site and attempt to download the file again. If you feel you received this message in error, please reference this code when contacting the ADC Support Team: V6
    – leoj
    Commented Mar 20, 2013 at 8:59
  • @leoj3n : What file am I trying to download? My session expired too but I was able to re-log in. I already downloaded the latest command line tools from April Commented Jun 30, 2013 at 16:39
  • 1
    This is the OS X Mavericks version, current as of Nov 2013 adcdownload.apple.com/Developer_Tools/…
    – Hanxue
    Commented Nov 29, 2013 at 15:23
37

As of big sur..

sudo rm -rf /Library/Developer/CommandLineTools
sudo xcode-select --install

Thanks homebrew maintainers for putting this helpful messaging in brew doctor

1
  • 1
    sudo xcode-select --install installs complete xcode
    – alper
    Commented Oct 8, 2022 at 15:09
25

The "unofficial" links are also available at

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

and 403: Forbidden unless logged in with a qualifying developer account. Free accounts have access to everything except prerelease software and full OS installs. In particular, the command-line tools packages that coincide with the release of Xcode 4.4 (the "July 2012" packages) were posted on July 27, for both Lion and Mountain Lion.

Unlike log files, deep-linking Web pages, and the Xcode Preferences window, this page also links to lots of other useful downloads for free and paid developers alike, including everything else that has been unbundled from Xcode (audio tools, accessibility tools, etc.), OS X kernel debug builds, and release versions of Xcode back to 1.0.

1
  • 1
    This is the answer that worked for me. This doesn't require a paid account and doesn't error out like the answers above. Commented Aug 8, 2016 at 16:06
15

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
  • 4
    You could download the standalone Command Line Tools and have access to everything that osx-gcc-installer provides. In fact, kenneth blogged about this kennethreitz.com/xcode-gcc-and-homebrew.html
    – Trung Lê
    Commented Feb 21, 2012 at 22:54
  • Thank god for people like Kenneth.
    – vhs
    Commented Oct 9, 2019 at 18:08
  • Not working above OS X Lion. don't waste your time to go and download Commented Sep 19, 2020 at 11:51
13
  1. Go to developer.apple.com/download/all/ (log in if you're not logged in)
  2. Expand the "View Details" tool tip for "Command Line Tools" of the version you need
  3. Download the .dmg file of those Command Line Tools
  4. Once the .dmg file is downloaded, double click it and install it

A screenshot showing Command Line Tools for Xcode 14.1 with the View Details dropdown clicked

12

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
    
10

You can automate the installation of Command-Line Tools in bash. I needed to do this when I was automating the developer onboarding setup process.

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'
0
8

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.

1
  • You can also make an alias in your .bashrc file to make 'git' use 'xcrun git' so that your git command is the same as everyone else's cocoanetics.com/2012/07/…. Commented Jan 16, 2013 at 18:45
3

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

3

By updating my Mac to the latest Mac OS (ie Big Sur), everything broke down to repetition request of installing Xcode-select.

It might seem weird, but I solved the problem by reinstalling & updating to the latest Xcode.

This is just my experience to solve the problem.

1

try going into Xcode > Preferences... > Downloads and clicking the button with a downward arrow in a circle next to command line tools.

1

xcode command line tools can be downloaded from here: https://developer.apple.com/downloads/index.action#

April 2014 version direct download link (for developers who just want to get started right away) 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

0
1

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

For OS X 10.9, you simply install Xcode. The Command Line Tools are bundled with Xcode. From Technical Note TN2339, Building from the Command Line with Xcode FAQ:

Downloading command-line tools is not available in Xcode for OS X 10.9. How can I install them on my machine?

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

0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.