Fix Xcode Command Line Tools error on Mac OS X

I had replaced my HDD with an SSD and then successfully transferred the applications from the HDD to the new installed SSD.

Previously I have ‘wine‘ to run Windows emulation programs and ‘minicom‘ to run serial communications which were both installed via MacPorts. It seems that the MacPorts applications were not transferred by using Apple Migration Assistant app. So I need to re-install those MacPort-based programs.

However when I tried to install them via port, I got the following errors

$ sudo port install wine
Password:
Warning: The Command Line Tools for Xcode don't appear to be installed; most ports will likely fail to build.
Warning: See http://guide.macports.org/chunked/installing.xcode.html for more information.
--->  Computing dependencies for wineError: Unable to execute port: can't read "build.cmd": Failed to locate 'make' in path: '/opt/local/bin:/opt/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin' or at its MacPorts configuration time location, did you move it?

The error messages said that the Xcode Command Line Tools is not installed.
Then when I run ‘xcodebuild -license’ I encountered the following error:

$ sudo xcodebuild -license
xcrun: Error: could not stat active Xcode path '/Volumes/Macintosh HD/Applications/Xcode.app/Contents/Developer'. (No such file or directory)

which said that the Xcode path is not exist.

Here are the steps how to solve these issues

1. Run Xcode then go to Preferences > Downloads > Components. Make sure that the Command Line Tools component is installed. If not, install it by clicking the Install button!

Install XCode command line tools

2. Still in Preferences window, click the Locations section. Make sure that the Command Line Tools option is set to the correct app.

Xcode command line tools location

Re-run the port install. The issues should be fixed.