97

How do I determine what version(s) of xcode command line tools I have?

I tried doing

$ gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix

Is the Apple LLVM version the same as the version of xcode command line tools?

1
  • 2
    +1. It was really hard to craft a Google search to find an answer to this. I searched xcode command line tools installed version but got a lot of irrelevant matches. Btw, did Dog G.'s answer work for you?
    – Kelvin
    Commented Jun 15, 2016 at 18:20

7 Answers 7

106

Finding the CLI version number depends on the combination of which particular OS and which particular CLI Tools are installed. One of these should work:

On versions 10.9 and later (OS X Yosemite to macOS Monterey):

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

on OS X 10.8 (Mountain Lion):

pkgutil --pkg-info=com.apple.pkg.DeveloperToolsCLI
8
  • 31
    If they ever change the pkg name again, running pkgutil --pkgs | grep -i tools should help locate it.
    – Kelvin
    Commented Jun 15, 2016 at 18:29
  • 5
    On macOS Catalina com.apple.pkg.CLTools_Executables is still a good package to use for this: pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep version version: 11.3.0.0.1.1574140115
    – phatblat
    Commented Dec 13, 2019 at 18:37
  • 2
    @phatblat: Catalina 10.15.4, fm zsh CL: pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep version ==> No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'. Ideas??
    – Seamus
    Commented Apr 18, 2020 at 6:11
  • 1
    @Seamus, sounds like you don't have the CLI tools installed. That's what I get on 10.15.4 when looking for the old package name: pkgutil --pkg-info=com.apple.pkg.DeveloperToolsCLI No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'. I'm on a fresh 10.15.4 install that I installed the CLI tools on first before installing Xcode 11.4.1: pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep version version: 11.4.1.0.1.1586360307
    – phatblat
    Commented Apr 23, 2020 at 18:17
  • 1
    @phatblat: Thanks for the feedback, but the CL tools are definitely installed - wonder why Apple leaves this versioning business so poorly defined?... Oh scratch that - I think I know the answer :)
    – Seamus
    Commented Apr 23, 2020 at 20:01
18

I had XCode Commandline Tools installed for sure, but not XCode itself.

None of the available answers to get the version worked. pkgutil didn't give me the package of the XCode Commandline Tools, with none of the suggested package names.

Not having XCode installed (and having no need for it), I could not look in settings dialogs of that either.

xcode-select --version only gave me the version of xcode-select itself, with no clue as to the commandline tools version.

softwareupdate --list told me everything was up to date.

However I knew that my version must be out of date as the installer for one of homebrew packages told me so!

How I finally found out what version of the XCode Commandline Tools is installed I stumbled upon the command:

softwareupdate --history

Which listed 12.3 as the last version it updated...

Display Name                                       Version    Date                  
------------                                       -------    ----                  
Safari                                             14.0       04/11/2020, 12:26:12  
Command Line Tools for Xcode                       12.1       04/11/2020, 22:38:33  
Safari                                             14.0.2     15/12/2020, 16:38:27  
Safari                                             14.0.1     15/12/2020, 16:38:27  
Command Line Tools for Xcode                       12.3       15/12/2020, 16:38:27  
macOS Big Sur                                      11.2.1     14/02/2021, 20:57:56  
macOS Big Sur 11.2.2                               11.2.2     08/03/2021, 09:02:20  

So when you know for sure the commandline tools are installed (because, for instance, xcode-select --install tells you so) but none of the other methods works, check softwareupdate --history!

1
  • 3
    This is much more useful/reliable than Doc G.'s answer and its recyclers, since in this way you can get the required information without needing to know the arcana of packages, version-dependent names, etc.
    – hmijail
    Commented Dec 11, 2022 at 3:27
13

In terminal do

xcodebuild -version

Or, if you know the full path of xcodebuild, you can prepend that. In my case, I did

/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -version

example output:

Xcode 10.1
Build version 10B61

(adapted from https://www.garron.me/en/bits/what-xcode-version-am-i-running.html).

5
  • 8
    Using Mojave here. xcodebuild -version was what I was looking for. Commented Feb 25, 2019 at 6:11
  • 17
    This does not work if Xcode is not installed. If only the CommandLineTools are installed, this path does not exist. Commented Mar 12, 2020 at 20:20
  • 8
    But the question was for the command line tools - aren't they at different version numbers?
    – Seamus
    Commented Apr 18, 2020 at 6:06
  • 1
    Doesn't exist in Big Sur
    – Dr.jacky
    Commented Nov 4, 2021 at 15:56
  • 2
    This only displays the Xcode version not the Command Line tools version - which can be different.
    – Pierz
    Commented Jun 30, 2022 at 20:07
11

For versions of macOS X 10.9 Mavericks and later, this code will provide you the version of both Xcode and Command Line Tools for Xcode, if either are installed:

# Xcode
if pkgutil --pkgs=com.apple.pkg.Xcode >/dev/null; then
    echo Xcode: $(pkgutil --pkg-info=com.apple.pkg.Xcode | awk '/version:/ {print $2}')
else
    echo Xcode: not installed
fi

# Command Line Tools for Xcode
if pkgutil --pkgs=com.apple.pkg.CLTools_Executables >/dev/null; then
    echo CommandLineTools: $(pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | awk '/version:/ {print $2}')
else
    echo CommandLineTools: not installed
fi
1
  • 1
    You can use pkgutil --pkgs=com.apple.pkg.Xcode > /dev/null (and pkgutil --pkgs=com.apple.pkg.CLTools_Executables > /dev/null) to avoid having to grep the result of pkgutil --pkgs.
    – nohillside
    Commented Mar 13, 2020 at 17:07
6

For modern versions of xcode the command xcode-select --version will display the version number of command line tools, whether or not Xcode.app is installed.

I'm answering against the more recent version (where the tools actually are in the Xcode.app pkg), but I'm pretty sure that if the path & output returned by xcode-select -p, gcc -v, and llvm-gcc -v/clang -v are harmonious then they should be the same, i.e.

$ xcode-select -p
/Applications/Xcode.app/Contents/Developer

$ gcc -v
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix

$ llvm-gcc -v
Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix

$ clang -v
Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix

Note that llvm-gcc is a link to clang,

$ls -al /usr/bin/llvm-gcc
lrwxr-xr-x  1 root  wheel  5 Oct 19  2014 /usr/bin/llvm-gcc -> clang

so the output of llvm-gcc -v and clang -v should be identical although that may or may not be the case for you (see https://stackoverflow.com/a/5708732/602581 for some more details)

1
  • 9
    The version that these tools output isn't necessarily the same as the Xcode command line tools version. Example, clang --version returns Apple LLVM version 7.3.0 (clang-703.0.31), while Doc G.'s pkgutil command returns version: 7.3.1.0.1.1461711523.
    – Kelvin
    Commented Jun 15, 2016 at 18:28
2

Here's a nice way I've found to scriptify things,

BUILD_TOOL_PATH=$(xcode-select -p)

if [[ ${BUILD_TOOL_PATH} == "/Applications/Xcode.app/Contents/Developer" ]]; then
    BUILD_TOOL_VER=$(xcodebuild -version | /usr/bin/grep "Xcode" | sed -e 's/Xcode //' | cut -d. -f1)
elif [[ ${BUILD_TOOL_PATH} == "/Library/Developer/CommandLineTools" ]]; then
    BUILD_TOOL_VER=$(pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | /usr/bin/grep "version" | sed -e 's/version: //' | cut -d. -f1)
else
    echo "Error: On macOS, either Xcode or the Command Line Tools must be installed!"
    exit 1
fi

Obviously, you can remove the else/error condition. If you need to do something for a specific version of Xcode/CLT (relevant to the time of this answer), you can for example,

if [[ ${BUILD_TOOL_VER} -ge 15 ]]; then
    export LDFLAGS="-Wl,-ld_classic"
fi
1
pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep version

Works for Montery (OS 12.xx)

2
  • How deos this differ from other answers like apple.stackexchange.com/a/181994/237
    – mmmmmm
    Commented Jan 12, 2022 at 16:57
  • 1-Confirmed to work with newest version of MacOS 2-included grep to filter out extraneous information
    – lodeOfCode
    Commented Jan 12, 2022 at 17:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .