I solved this in the following way…
- Open Xcode
- Go to Xcode preferences (CMD+,)
- Find the Location tab
- In the last drop down (Command line tools), select the appropriate Xcode version. In my case no version was selected and that was casuing the issue.
Note: The terminal method shown in other answers does the same thing.