title: `xcodebuild` not working from terminal
body: <p>After I used migration assistant to migrate data from my old mac to a new one I can no longer use Xcode command line tools. Whenever I run any <code>xcodebuild</code> command in terminal (even <code>xcodebuild</code> with no parameters) I get the following error:</p>
  <pre><code>dyld: Library not loaded: @rpath/DVTFoundation.framework/Versions/A/DVTFoundation
    Referenced from: /usr/bin/xcodebuild
    Reason: image not found
  Abort trap: 6
  </code></pre>
  <p>When I run <code>which xcodebuild</code> I get <code>/usr/bin/xcodebuild</code>.</p>
  <p>When I run <code>xcode-select -p</code> I get <code>/Applications/Xcode.app/Contents/Developer</code>.</p>
  <p>Strangely, if I go to <code>/Applications/Xcode.app/Contents/Developer/usr/bin</code> and call <code>./xcodebuild</code> I <strong>do not</strong> get the error above.</p>
  <p>Here is what I tried:</p>
  <ol>
  <li>Installing command line tools using <code>xcode-select --install</code>.</li>
  <li>Uninstalling command line tools located in <code>/Library/Developer/CommandLineTools/</code>.</li>
  <li>Performing <code>sudo xcode-select --switch /Library/Developer/CommandLineTools/</code>.</li>
  <li>Performing <code>sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/</code>.</li>
  </ol>
  <p>None of these resolves my problem.</p>
  <p>I am running Xcode 9.4.1 and macOS High Sierra 10.13.5.</p>
  <h1>UPDATE 1</h1>
  <p>I tried following <a href="https://www.client9.com/uninstall-xcode-on-macos-sierra/" rel="noreferrer">this guide</a> to uninstall Xcode and all command line build tools completely. The strange thing is, once I followed all the steps, running <code>xcodebuild</code> command produced the same result as before. And <code>xcodebuild</code> was still located in <code>/usr/bin</code>.</p>
  <h1>UPDATE 2</h1>
  <p>If I install command line tools using <code>xcode-select --install</code> and go to <code>/Library/Developer/CommandLineTools/usr/bin</code> running <code>xcodebuild</code> from that location <strong>does produce</strong> the same error. So, running <code>xcodebuild</code> which comes pre-installed with Xcode produces no error, but the one from the command line tools does produce the error. It is puzzling and also suggests that when I try to remove all command line tools, the ones left in my <code>/usr/bin</code> are the ones which do not come with Xcode.</p>
  <p>I tried deleting them, but I am unsuccessful even with the <code>sudo</code> command.</p>
  <h1>UPDATE 3</h1>
  <p>I've found a workaround. To ensure that <code>xcodebuild</code> command uses the tool located in <code>/Applications/Xcode.app/Contents/Developer/usr/bin</code> rather than the one located in <code>/usr/bin</code>, I added the following line to my <code>.bash_profile</code>:</p>
  <p><code>export PATH=&quot;/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH&quot;</code></p>
  <p>This approach works, but my question remains. I do not understand why I had this problem in the first place. I have double checked - my <code>PATH</code> does not contain <code>/Applications/Xcode.app/Contents/Developer/usr/bin</code> on my old Mac and everything works just fine there.</p>
  <p>Looks like for some reason, <code>xcodebuild</code> located in <code>/usr/bin</code> got corrupted and couldn't get updated in any way.</p>