Wilson Mar bio photo

Wilson Mar

Hello!

Email me Calendar Skype call

LinkedIn Twitter Gitter Instagram Youtube

Github Stackoverflow Pinterest

Xcode IDE contains Command-Line utilities, which can also be installed separately. But separate Command-Line installer cause errors for use by Homebrew, Python, and other development tools

US (English)   Español (Spanish)   Français (French)   Deutsch (German)   Italiano   Português   Estonian   اَلْعَرَبِيَّةُ (Egypt Arabic)   中文 (简体) Chinese (Simplified)   日本語 Japanese   한국어 Korean

Overview

This tutorial describes the installation and usage of gcc, make and other executable utilities from Apple which Homebrew, Python, and many other development tools need.

NOTE: Content here are my personal opinions, and not intended to represent any employer (past or present). “PROTIP:” here highlight information I haven’t seen elsewhere on the internet because it is hard-won, little-know but significant facts based on my personal research and experience.

Overlapping installers!

The executables from Apple are installed two separate ways. Imagine a Venn diagram of overlapping circles:

  • CommandLineTools at /Library/Developer/CommandLineTools

  • Xcode IDE at ~/Applications/Xcode.app

Each has a separate install procedure.

Xcode is Apple’s free IDE developers use to create custom programs for all Apple devices (macOS, iPhone, iPad, Apple Watch). Increasingly, Machine Learning developers are using the Swift language.

Because XCode.app is very large (several Gigabytes), developers who do not create Apple programs can save disk space by not installing it. Instead, they install just the CommandLineTools needed by Homebrew and others.

About Xcode.app

Since the Apple Store only handles individual .app files, other mechanisms are needed to install additional programs needed as a pre-requisite by Homebrew, Python, and other development programs.

BTW Xcode only works on macOS. There is no Windows PC version.

PROTIP: Skip Apple’s websites and App. Click here for install instructions (below).

Otherwise, read on for a run-around.

  1. Use an internet browser to view Apple’s Xcode marketing page at:

    https://developer.apple.com/Xcode

    Xcode “includes everything you need to create amazing apps for all Apple platforms. Now Xcode and Instruments look great in the new Dark Mode on macOS Mojave. The source code editor lets you transform or refactor code more easily, see source control changes alongside the related line, and quickly get details on upstream code differences. You can build your own instrument with custom visualization and data analysis. Swift compiles software more quickly, helps you deliver faster apps, and generates even smaller binaries. Test suites complete many times faster, working with a team is simpler and more secure, and much more.”.

    BTW the “Apple platforms” include MacOS, iPhone, iPad, Apple TV, and Apple Watch.

Xcode does not come with macOS because of its large size and because many users of macOS don’t need it to do software development.

Developers who use another IDE (such as Visual Studio, Eclipse, etc.) would only need to install Xcode’s command line utilities for the GCC compiler Python needs to build code.

PROTIP: Newer versions of Xcode installer also installs a Git client.


cc and gcc needed

Homebrew, Python, and many other development tools need the cc, gcc, make and other executable utilities from Apple.

  1. Verify the version of GCC installed:

    gcc --version

    If Xcode.app was installed, you would see (at time of writing):

    Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
    Apple clang version 13.0.0 (clang-1300.0.29.3)
    Target: x86_64-apple-darwin21.1.0
    Thread model: posix
    InstalledDir: /Library/Developer/CommandLineTools/usr/bin
    

    Previously, it was instead:

    Apple LLVM version 10.0.1 (clang-1001.0.46.4)
    InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
    

    If CommandLineTools is installed, you would see (at time of writing):

    Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
    Apple clang version 11.0.3 (clang-1103.0.32.62)
    Target: x86_64-apple-darwin19.4.0
    Thread model: posix
    InstalledDir: /Library/Developer/CommandLineTools/usr/bin
    

    If “Command not found” appears, either install CommandLineTools or install XCode.app, then return here.

    xcrun for path

  2. Identify the path of the gcc

    xcrun --find gcc

    If Command Line Utilities is installed, the response is:

    /Library/Developer/CommandLineTools/usr/bin/gcc

    If Xcode.app is installed, the response is:

    /Applications/Xcode.app/Contents/Developer/usr/bin/gcc

    If neither is installed:

    xcrun: error: active developer path ("/Library/Developer/CommandLineTools") does not exist
    Use `sudo Xcode-select --switch path/to/Xcode.app` to specify the Xcode that you wish to use for command line developer tools, or use `Xcode-select --install` to install the standalone command line developer tools.
    See `man Xcode-select` for more details.
    

    The same for make.

    Again, if “Command not found” appears, either install CommandLineTools or install XCode.app, then return here.

    Files and Folders

    Let’s see what is in those folders:

  3. If CommandLineTools was installed:

    ls -al /Library/Developer/CommandLineTools
    

    The response would be:

    Library      SDKs    usr
  4. If Xcode.app was installed:

    ls -al /Applications/Xcode.app/Contents/Developer/
    

    The response would have more than what’s in CommandLineTools:

    Applications Library      Makefiles    Platforms    Toolchains   Tools        usr

    Xcode.app Version

  5. From within a Terminal, type:

    /usr/bin/Xcodebuild -version
    

    If Command Line Tools was installed, you would see:

    Xcode-select: error: tool 'Xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

    If Xcode is installed, you would get a version code that should match up with the Build Number on the Apple web page:

    Xcode 10.2.1
    Build version 10E1001
    
  6. For a more precise version number and other info (macOS Mavericks version and up):

    pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
    

    A sample response, at time of writing:

    package-id: com.apple.pkg.CLTools_Executables
    version: 13.1.0.0.1.1633545042
    volume: /
    location: /
    install-time: 1637303193
    groups: com.apple.FindSystemFiles.pkg-group
    

    The previous command was constructed based on a search of tools package names:

    pkgutil --pkgs | grep -i tools
    

    The response:

    com.apple.pkg.CLTools_Executables
    com.apple.pkg.CLTools_SDK_macOS1015
    com.apple.pkg.CLTools_SDK_macOS1014
    com.apple.pkg.CLTools_macOS_SDK
    ...
    

    xcode-select

    Unlike other programs, a xcode-select command is needed to designate where to find gcc and other Apple Developer utilities.

  7. In a Terminal window, find out what has been installed:

    xcode-select -p
    

    -p is the same as –print-path

    If XCode CLI was installed, you should see:

    If the Xcode-select command is not found, choose to either install Command Line Tools or install the full Xcode IDE.

    /Library/Developer/CommandLineTools

    If XCode.app was installed, you should instead see:

    /Applications/Xcode.app/Contents/Developer

    Specifying the XCode utility used

    PROTIP: Xcode.app cannot be installed if Command Utilities has already been installed. So the installation program needs to first check whether XCode.app or CommandLineTools is installed.

    Choose which one you want used:

  8. To specify use of the Xcode.app (IDE):

    sudo xcode-select --switch /Applications/Xcode.app
    
  9. To specify use of CommandLineTools:

    sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
    
  10. Reset

    sudo xcode-select -r

Install Command Line Utilities only

See https://developer.apple.com/library/archive/technotes/tn2339/_index.html and http://osxdaily.com/2014/02/12/install-command-line-tools-mac-os-x

  1. To install Command Line Utilities:

    xcode-select --install

    Alternately, this script:

    xcode-select --install > /dev/null 2>&1
    if [ 0 == $? ]; then
     sleep 1
     osascript <<EOD
    tell application "System Events"
     tell process "Install Command Line Developer Tools"
         keystroke return
         click button "Agree" of window "License Agreement"
     end tell
    end tell
    EOD
    else
     echo "Command Line Developer Tools are already installed!"
    fi
    

    A shell script uses these commands to not require manual clicking on the dialog that pops up (below):

    #!/bin/sh
    # Create placeholder file checked by CLI updates' .dist code in Apple's SUS catalog:
    touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress;
    # Find the CLI Tools update:
    PROD=$(softwareupdate -l |
      grep "\*.*Command Line" |
      head -n 1 | awk -F"*" '{print $2}' |
      sed -e 's/^ *//' |
      tr -d '\n')
    # Unless "No new software available.", install it:
    softwareupdate -i "$PROD" -v;
    

    Xcode-select-prompt-444x148

  2. If you see this pop up, manually click “Install”, “Agree”, then “Install” to the “Updates Available” pop-up.

  3. CAUTION: The large number of files means it can a long time. It took 13 minutes on my 10mbps line.

  4. When you see “The software was installed.”, click “Done” to dismiss the pop-up.

  5. If you have the tree utility installed:

    tree /Library/Developer/CommandLineTools | tail -1

    Would yield (at time of writing):

    16143 directories, 72910 files

UnInstall Command Line Tools

PROTIP: This is also how you upgrade Command Line Tools.

  1. Go to the parent folder where Command Line Tools is installed:

    cd /Library/Developer 
    
  2. Get a list of its folders:

    ls CommandLineTools
    

    If Command Line Tools were installed, the response would be :

    Library	SDKs	usr
  3. Remove all files in that folder, provide a password for elevated permissions to get all the files:

    sudo rm -rf /Library/Developer/CommandLineTools
    

    The response is a lot of files removed (to the Trash).

    Now install CommandLineTools (or install the full Xcode IDE).

    CAUTION: On a Mac M1 (Apple Silicon chip, macOS 12.0 Monterey), after installed the Command Line Tools then uninstalled them by deleting /Library/Developer/CommandLineTools and running sudo xcode-select -r, I was still getting updates to the tools in System Preferences > Software Update.

    The files below are protected by SIP: to delete them, I had to disable SIP first (ie disable SIP, delete the files, re-enable SIP).

    Indeed, the receipts are at /Library/Apple/System/Library/Receipts, in the form of files

    • com.apple.pkg.CLTools_Executables.{bom,plist}
    • com.apple.pkg.CLTools_SDK_macOS*.{bom,plist}
    • com.apple.pkg.CLTools_macOS_SDK.{bom,plist}

Xcode IDE install from Terminal

  1. Make sure you have at least 13GB free on your hard-drive before attempting installation.

    1. Click the Apple icon to select “About this Mac”.
    2. Click “Storage” tab.

  2. In an internet browser, get to the “Mac App Store Preview” for Xcode at
    https://apps.apple.com/us/app/Xcode/id497799835?mt=12

    Xcode-web-preview.png

  3. Click View in Mac App Store, then “Open App Store.app” in the pop-up.

  4. Provide your Apple ID and password. Get one if you don’t already have one.

    PROTIP: DO NOT install a beta version of Xcode.

    The blue “OPEN” icon appears at the upper-right when the app is installed. But don’t click it because we are done.

  5. In Finder, look for Xcode.app in the /Applications folder.

    Alternately, on the Touchpad pinch 4 fingers together to click the App Store. Type enough of “Xcode” to filter out others.

  6. To view the version, cursor to the top of the screen and click the program name next to the Apple icon to select “About Xcode”:

    Xcode about 271x48

A) Initial install from Terminal CLI

  1. Open a Terminal.app console window at any directory to install -all the latest Xcode from Apple:

    softwareupdate --install -a
    

    The response on Catalina version of macOS:

    Software Update Tool
     
    Finding available software
     
    Downloaded macOS Catalina 10.15.5 Update
    Installing macOS Catalina 10.15.5 Update
    Done.
    To install these updates, your computer must shut down. Your computer will automatically start up to finish installation.
    Installation will not complete successfully if you choose to restart your computer instead of shutting down.
    Please call halt(8) or select Shut Down from the Apple menu. To automate the shutdown process with softwareupdate(8), use --restart.
    
  2. Click the Apple icon at the upper-right corner and select “Shut Down…”.

    After starting again

  3. Set Apple’s licensing agreement bit:

    sudo xcodebuild -license
    
  4. Manually agree to the terms.

  5. Get the version number of the new version.

B) Initial IDE install using web App Store

  1. In an internet browser, https://developer.apple.com/download

  2. Sign in to Apple Developer with your email address then click the arrow icon. Enter your password, then click the arrow icon.

    Below is the “Software Update” approach:

    You’ll need to establish an Apple ID if you haven’t already.

  3. Click the cloud icon Download and provide your Apple ID.

  4. Go through Apple’s location verification if prompted.

    Xcode-select-ver

  5. Confirm your account.

  6. Click “Allow” to the pop-up “Do you want to download?”.

    Xcode size

  7. CAUTION: Make sure that your machine has enough free space available.

    These are massive files that may take a while to download if you don’t have a fast internet connection.

    NOTE: Each version of Xcode is related to a specific version of the Apple OS Mac operating system.

    File Date Download Unpacked
    Xcode_12.1 2020-10-01 10.5 GB 11.5 GB
    Xcode_11.5 2020-06-01 7.5 GB ? GB
    Xcode_10.2.1 2019-04-17 ? GB 6.1 GB
    Xcode_9.0 2017-09-19 . ? GB ? GB
    Xcode_8.2.1 8C1002 2016-12-19 ? GB ? GB
    Xcode_8_beta_2.xip 2016-07-05 5.9 GB 12.32 GB
    Xcode_7.31 2016-05-03 3.8 GB ?
    Xcode_4.1 2014- 2.9 GB ?
    Xcode_3.2.4 2014- 2.? GB ?
  8. Switch to Finder Downloads folder to watch progress on the file name ending with “Download”. The one with a clock icon which signifies downloading.

  9. Return to the versions instructions above to view the updated version.

  10. Delete the installer after you’re done, to reclaim disk space.


Xcode IDE Upgrade

Over time, Apple updates Xcode and its command line utilities.

  1. Click the Apple icon, then click System Preferences. Here is an example notification:

    Xcode-cli-update-436x98-4795

  2. Search for “Software Updates” or click the icon.
  3. Click “Update Now” if that appears. (but first do a backup.)
  4. Click “Agree” to the EULA.
  5. When done, view the version numbers installed.

Swift version

  1. Get the version of the Swift program used to develop iOS mobile apps:

    swift -version

    If you are on an Intel CPU, a sample response at time of this writing:

    Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)
    Target: x86_64-apple-darwin21.4.0
    

    If you are on an ARM (M1) CPU, a sample response at time of this writing:

    swift-driver version: 1.45.2 Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)
    Target: arm64-apple-macosx12.0
    

    If jamf installed Xcode, you’ll also see:

    [1]+  Done                    sudo rm -rf /Library/Developer/CommandLineToolsjamfselfservice://content?entity=policy

    The above appears regardless of whether Command Line Utilities or Xcode.app is installed.


Xcode FileMerge tool

Xcode graphically compares files and directories.

  1. Open Xcode. This takes a few seconds.

  2. Right-click on Xcode icon. Select “Open Developer Tool”. Select “FileMerge”.

  3. Specify one file to compare.

  4. Specify the other file to compare.

  5. Click “Compare”.

More on OSX

This is one of a series on Mac OSX: