157

I need to use gdb.

ps-MacBook-Air:AcoustoExport pi$ gdb
-bash: gdb: command not found

ps-MacBook-Air:AcoustoExport pi$ sudo find / -iname "*gdb*"
Password:
/usr/local/share/gdb
/usr/local/Cellar/isl/0.12.1/share/gdb
:

and:

ps-MacBook-Air:AcoustoExport pi$ ls -la /usr/local/share/gdb
lrwxr-xr-x   1 pi    admin   30 14 Jan 22:01 gdb -> ../Cellar/isl/0.12.1/share/gdb

Not quite sure what to make this, clearly it is something installed by homebrew. I don't know why it's there, I don't know whether I could use it instead. It isn't in the search path.

So I figure I need Xcode commandline tools.

Xcode is not currently available from the Software Update server

^ my current problem exactly. Comment on that question says "you can get this error if you have them already"

But how do I check whether I have them already?

Community
  • 1
  • 1
P i
  • 26,994
  • 34
  • 144
  • 244

8 Answers8

262
/usr/bin/xcodebuild -version

will give you the xcode version, run it via Terminal command

Danh
  • 5,716
  • 7
  • 27
  • 41
Rohit
  • 2,846
  • 1
  • 12
  • 15
  • 5
    To get only the version use the following command: /usr/bin/xcodebuild -version | sed -En 's/Xcode[[:space:]]+([0-9\.]*)/\1/p' – Werner Altewischer Sep 20 '18 at 06:54
  • 2
    I am getting error with the mentioned command. "-bash: /usr/build/xcodebuild: No such file or directory." I have confirmed that I have xcode by running command gcc --version, which gives the gcc details. I am on Mac OS X 10.13.6. – Gaurav Srivastava Sep 26 '18 at 21:37
  • @GAURAV SRIVASTAVA: it's `/usr/bin`, not `/usr/build`. In fact `xcodebuild` should be enough since `/usr/bin` is usually in your `PATH`. – Samuel Lelièvre Jul 25 '20 at 19:18
  • 25
    I get this `xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance`. i think – Gulam Hussain Aug 31 '21 at 01:51
  • @GulamHussain, see below answer by @Alex https://stackoverflow.com/a/42144725/311288 for cases where Xcode not installed and only `CommandLineTools` is available – Thomas B in BDX May 09 '22 at 10:15
53

First of all, be sure that you have downloaded it or not. Open up your terminal application, and enter $ gcc if you have not installed it you will get an alert. You can verify that you have installed it by

$ xcode-select -p
/Library/Developer/CommandLineTools

And to be sure then enter $ gcc --version

You can read more about the process here: Xcode command line tools for Mavericks

Siavash Alp
  • 1,372
  • 14
  • 14
  • 1
    @Pi What do you get when you enter $gcc --version? Do you get something like this: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn) – Siavash Alp Jan 22 '14 at 04:47
  • No, I get --prefix=/Applications/Xcode.app/Contents/Developer/usr. The remainder is the same as your printout. – P i Jan 22 '14 at 13:58
42

if you want to know the install version of Xcode as well as Swift language current version:

Use below simple command by using Terminal:

1. To get install Xcode Version

 xcodebuild -version

2. To get install Swift language Version

swift --version
Kiran Jadhav
  • 3,029
  • 23
  • 29
41

This command allows you to retrieve Xcode version when having only the CommandLineTools version installed:

pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep version

As per this answer to "Determine xcode command line tools version" on Ask Different

Notes:

  • Confirmed working on maxOS Sierra and Big Sur.
  • When only CommandLineTools is install without Xcode, using xcodebuild returns the following error:
# /usr/bin/xcodebuild -version
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
Thomas B in BDX
  • 2,422
  • 2
  • 25
  • 28
Alex
  • 10,175
  • 6
  • 60
  • 68
  • Thank you! This actually works when only *CommandLineTools* is installed and not actual *Xcode* and solves the error when running`/usr/bin/xcodebuild -version` : `xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance` – Thomas B in BDX May 09 '22 at 10:08
14

Thanks to the folks on Freenode's #macdev, here is some information:

In the old days before Xcode was on the app-store, it included commandline tools.

Now you get it from the store, and with this new mechanism it can't install extra things outside of the Xcode.app, so you have to manually do it yourself, by:

xcode-select --install

On Xcode 4.x you can check to see if they are installed from within the Xcode UI:

enter image description here

On Xcode 5.x it is now here:

enter image description here

My problem of finding gcc/gdb is that they have been superseded by clang/lldb: GDB missing in OS X v10.9 (Mavericks)

Also note that Xcode contains compiler and debugger, so one of the things installing commandline tools will do is symlink or modify $PATH. It also downloads certain things like git.

Jeroen Ooms
  • 30,444
  • 34
  • 124
  • 198
P i
  • 26,994
  • 34
  • 144
  • 244
4

If for some reason xcode is not installed under

/usr/bin/xcodebuild

execute the following command

which xcodebuild

and if it is installed, you'll be prompted with it's location.

1

You can open the Xcode app and go to preferences:

enter image description here

Boaz Frenkel
  • 568
  • 4
  • 14
0

For macOS catalina try this : open Xcode. if not existing. download from App store (about 11GB) then open Xcode>open developer tool>more developer tool and used my apple id to download a compatible command line tool. Then, after downloading, I opened Xcode>Preferences>Locations>Command Line Tool and selected the newly downloaded command line tool from downloads.