69

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
  • 1
    +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
    Jun 15, 2016 at 18:20

5 Answers 5

76

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
6
  • 24
    If they ever change the pkg name again, running pkgutil --pkgs | grep -i tools should help locate it.
    – Kelvin
    Jun 15, 2016 at 18:29
  • 4
    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
    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
    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
    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
    Apr 23, 2020 at 20:01
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
  • 7
    Using Mojave here. xcodebuild -version was what I was looking for. Feb 25, 2019 at 6:11
  • 9
    This does not work if Xcode is not installed. If only the CommandLineTools are installed, this path does not exist. Mar 12, 2020 at 20:20
  • 8
    But the question was for the command line tools - aren't they at different version numbers?
    – Seamus
    Apr 18, 2020 at 6:06
  • 1
    Doesn't exist in Big Sur
    – Dr.jacky
    Nov 4, 2021 at 15:56
  • 1
    -1. This no longer works.
    – danorton
    Apr 1 at 15:52
9

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
2
  • 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
    Mar 13, 2020 at 17:07
  • Thanks for above code! worked well.
    – Natsfan
    Mar 13, 2020 at 17:46
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
  • 7
    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
    Jun 15, 2016 at 18:28
-2
pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep version

Works for Montery (OS 12.xx)

2

You must log in to answer this question.

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