`xcodebuild` not working from terminal - xcode

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 xcodebuild command in terminal (even xcodebuild with no parameters) I get the following error:
dyld: Library not loaded: #rpath/DVTFoundation.framework/Versions/A/DVTFoundation
Referenced from: /usr/bin/xcodebuild
Reason: image not found
Abort trap: 6
When I run which xcodebuild I get /usr/bin/xcodebuild.
When I run xcode-select -p I get /Applications/Xcode.app/Contents/Developer.
Strangely, if I go to /Applications/Xcode.app/Contents/Developer/usr/bin and call ./xcodebuild I do not get the error above.
Here is what I tried:
Installing command line tools using xcode-select --install.
Uninstalling command line tools located in /Library/Developer/CommandLineTools/.
Performing sudo xcode-select --switch /Library/Developer/CommandLineTools/.
Performing sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer/.
None of these resolves my problem.
I am running Xcode 9.4.1 and macOS High Sierra 10.13.5.
UPDATE 1
I tried following this guide to uninstall Xcode and all command line build tools completely. The strange thing is, once I followed all the steps, running xcodebuild command produced the same result as before. And xcodebuild was still located in /usr/bin.
UPDATE 2
If I install command line tools using xcode-select --install and go to /Library/Developer/CommandLineTools/usr/bin running xcodebuild from that location does produce the same error. So, running xcodebuild 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 /usr/bin are the ones which do not come with Xcode.
I tried deleting them, but I am unsuccessful even with the sudo command.
UPDATE 3
I've found a workaround. To ensure that xcodebuild command uses the tool located in /Applications/Xcode.app/Contents/Developer/usr/bin rather than the one located in /usr/bin, I added the following line to my .bash_profile:
export PATH="/Applications/Xcode.app/Contents/Developer/usr/bin:$PATH"
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 PATH does not contain /Applications/Xcode.app/Contents/Developer/usr/bin on my old Mac and everything works just fine there.
Looks like for some reason, xcodebuild located in /usr/bin got corrupted and couldn't get updated in any way.

Related

I can not do a "pod install" in CocoaPods

I can not do a "pod install" in any project.
But the thing is that before it could.
What has changed from before to now?
Basically I have installed the new Xcode 10.1 and the new Mojave operating system.
Before I could do all the pod functions and not now. The error that I get is the following:
The Podfile is the following:
EDIT:
If I write:
xcode-select -p
If I write:
xcode-select -s /Applications/Xcode.app/Contents/Developer
Any idea what it can be? Nor did I just see what the error is. Do you see it? I have tried different solutions than those proposed but they do not work ... It's stressful !!
Execute this command in Terminal and try again:
xcode-select -s /Applications/Xcode.app/Contents/Developer
And be sure to update your Cocoapods spec repository by running pod repo update before pod install
Description:
The error is because the wrong path was set as the Xcode Command Line Tools. this can lead to many problems such as git error, C compiler error etc.
Always be sure your Xcode Command Line Tools path has been set to embedded Command Line Tools in Xcode app.

"xcrun: error: active developer path… does not exist, use xcode-select --switch" when trying to run git. How to fix?

I have been trying to instal the Git on my mac, But every time I use the command $git --version.
I get the following error
xcrun: error: active developer path ("/Volumes/Xcode/Xcode.app/Contents/Developer") does not exist, use xcode-select --switch path/to/Xcode.app to specify the Xcode that you wish to use for command line developer tools (or see man xcode-select)
I have already installed the Xcode on my mac for iOS App development.
I am not sure what this error is trying to say.
My case:
I removed XCode. JetBrains integration with git - breaks. Found this error in terminal.
My soltuion:
I don't want to download XCode to restore PyCharm. So I ran:
sudo xcode-select --reset
So from discussion in the comments above, it seems the right fix here is just to run the command /usr/bin/xcode-select -switch once (i.e., run it with the full path to the executable, rather than just as xcode-select) with /Applications/Xcode.app/Contents/Developer/ as the argument:
sudo /usr/bin/xcode-select -switch /Applications/Xcode.app/Contents/Developer
After running that once, everything should work as expected from then on.
sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools
and reboot your computer.
Try this below answer. It's worked for me.
Open your Xcode Preferences,
--> Select Locations
--> Select your specific Xcode version in Command Line Tools
It was easier for me to let Xcode pick the install location of Command Line Tools for me, instead of the other way around. After downloading the .xip file from the Apple Developer downloads page, expanding the compressed contents, and installing Xcode.App, I was able to open it using Spotlight.
And open preferences:
And select my Command Line Tools under "Locations".
You can install git via the brew package manager for Mac. I recommend installing software this way since it's a great way to manage your installed packages in one place. For example, you can do brew update to get a list of the latest package updates, or brew upgrade to upgrade all of your software installed through brew.
To install brew, open a terminal window and run:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Update your brew packages with brew update
Install git with brew install git
I had installed git, then returned to a terminal window open prior to the installation. I try running command git --version and this raised error message below. To resolve, I ran command source /etc/profile in same terminal window. BTW, terminal window is inside my Webstorm and my end goal is to git init and setup git for my new reactjs project. Happy coding!
The error:
xcrun: error: active developer path ("/Volumes/Xcode/Xcode.app/Contents/Developer") does not exist, use \`xcode-select --switch path/to/Xcode.app\` to specify the Xcode that you wish to use for command line developer tools (or see \`man xcode-select\`)

Cannot install command line tools due to out of date xcode-select

For weeks I've been trying to work this out.
When I run bash install_script.sh file as yt-project ( http://yt-project.org/#getyt ) instructs, it outputs this error:
gcc -fPIC -c blocksort.c
make: gcc: No such file or directory
make: *** [blocksort.o] Error 1
I got into contact with someone from the yt-users mailing list who had me check my version of xcode. I ran xcode-select -version and I recieve:
xcode-select version 2003.
This is definitely outdated.
I try to run xcode-select --install to ensure I have CLT, but it only feeds me back the menu of options to input into xcode-select. Nothing occurs.
I installed CLT directly from the developer website, as in Xcode 5.0 and later it is not in Preferences->Downloads. It seemed to install correctly, but it seems that Xcode itself installed incorrectly if I am unable to get a version number higher than 2003.
I tried uninstalling and reinstalling Xcode, but the problems did not change. As per xcode-select --install not running I checked the path on Xcode and it seemed correct. The output of xcodebuild -version is
Error: Can't run /Library/Developer/CommandLineTools/usr/bin/xcodebuild (no such file).
I tried the command listed here Can't install Command Line Tool, "xcode-select --install" doesn't work after confirming that I do not have a /Library/Developer folder.
The path for xcode-select --print-path is
/Library/Developer/CommandLineTools
When I do gcc --version it returns
-bash: gcc: command not found
How do I get the correct xcode-select binary?
I am very amateur at command line and there could be any number of assumptions that are incorrect that I fell into.
Thank you for your help!

Xcode is not currently available from the Software Update server

I have problems with my macport after update to OS X 10.9.
I try to follow this manual https://trac.macports.org/wiki/Migration to fix them.
But when I install Command Line Tools:
xcode-select --install
I get message
Can't install the software because it is not currently available from
the Software Update server.
Meanwhile I successfully updated my other machine to OS X 10.9. and installed command-line tools with no problems, so they must be available.
What is the problem here?
You can download the command line tools for OS X Mavericks manually from here:
https://developer.apple.com/downloads/index.action?name=for%20Xcode
For OSX 10.11 or more you can download from here https://developer.apple.com/download/more/.
(The link in the accepted answer doesn't display command line tools for El Capitan (OSX 10.11))
If you are trying this on a latest Mac OS X Mavericks, command line tools come with the Xcode 5.x
So make sure you have installed & updated Xcode to latest
after which make sure Xcode command line tools is pointed correctly using this command
xcode-select -p
Which might show some path like
/Applications/Xcode.app/Contents/Developer
Change the path to correct path using the switch command:
sudo xcode-select --switch /Library/Developer/CommandLineTools/
this should help you set it to correct path, after which you can use the same above command -p to check if it is set correctly
I faced same problem of Can't install the software because it is currently not available from the Software Update Server. You may try following steps instead to make the Software Update initiate update for the Command Line Tools.
Check if Command Line Tools Update is mentioned in your list of softwares to be updated by using following command: softwareupdate -l
If Command Line Tools Update is not mentioned in that list, then manually make it part of the list using following command which will create a temporary file: sudo touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
Verify that the list now has the Command Line Tools mentioned by running softwareupdate -l again.
Now, press Cmd+Space to initiate Mac's Spotlight Search. Search for Software Update. Start the Software Update.
That will show you following kind of dialog for installing the Command Line Tools. Install away the update and be merry. :)
Remove the temporary file created in Step 2: sudo rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress.
I deleted the command tools directory given by xcode-select -p due to npm gyp error.
xcode-select failed to install the files with the not available error.
I ran the Xcode application and the command tools installed as part of the startup.
npm worked.
However this didn't fully fix the tools. I had to use xcode-select to switch the path to the Developer directory within the Xcode application directory.
sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
MacOS catalina.
I just got the same error after I upgraded to 10.14 Mojave and had to reinstall command line tools (I don't use the full Xcode IDE and wanted command line tools a la carte).
My xcode-select -p path was right, per Basav's answer, so that wasn't the issue.
I also ran sudo softwareupdate --clear-catalog per Lambda W's answer and that reset to Apple Production, but did not make a difference.
What worked was User 92's answer to visit https://developer.apple.com/download/more/.
From there I was able to download a .dmg file that had a GUI installer wizard for command line tools :)
I installed that, then I restarted terminal and everything was back to normal.
I know this is an old post but I also ran into this problem today. I found out that when I executed sudo softwareupdate -l the Command Line Tools were listed as an update, so I installed them using sudo softwareupdate -i -a.
This error can occur if you are using a software update server which doesn't host the required package.
You can check this by running
defaults read /Library/Preferences/com.apple.SoftwareUpdate
and seeing if you have an entry called CatalogURL or AppleCatalogURL
You can point back at the Apple software update server by either removing this entry or using the command
sudo softwareupdate --clear-catalog
And then run the command line tools install again.
I got the same issue on MacOS Catalina.
I think I identified the root cause: I have switched the default Apple ID account and the new one was not activated as a Developer account. When I ran the xcode-select --install command, I got the same error as stated in the issue description.
After reading this post on stackoverflow, I went on https://developer.apple.com/downloads and I was asked to accept Developers terms. I think it enabled my account as a developer one. Then, I tried to run xcode-select --install again and it worked.
The command
xcode-select --install
proposes 3 options: Get Xcode; Not Now; Install.
When I choose to get full Xcode the command finished successfully. It took a while, but this way I was able to complete all macports migration instructions.
Once you get the command line tools loaded as described by Nikos M in his excellent answer above you will need to agree to the gcc license and if you are using ruby gems you may need to link llvm-gcc as gcc-4.2.
If you do not do these the gem install will report "You have to install development tools first." after you have already installed them.
The steps are:
sudo gcc
sudo ln -s /usr/bin/llvm-gcc /usr/bin/gcc-4.2
The gcc must be run once under sudo so Apple can update their license info, you don't need an input file, it will update the license before it checks its arguments. The link is needed so that ruby 1.9 can find the compiler when building certain gems, such as the debugger. This may be fixed in ruby 2.x, but I'll cross that bridge when I get there.
I had to run Xcode.app and agree to the License Agreement
Setup: Brand new MacBook with Mavericks, then brew install and other c/l type things 'just work'.
I solved this by going to the App Store and installing Xcode.
It was a pretty large 11GB install, so this is probably overkill. But, as a last resort, it seems to have solve my issues. In the middle of the installation (well around 10GB), Mac OS told me there was an update to Command Line Tools for Xcode. Performing this installation won't fix anything until Xcode is fully installed.
Once the install is done, it should start working (after you accept the license agreement).
Command + Space
Search for Xcode
Open it and accept license
Then run again from terminal xcode-select --install
Had the same issue and was getting the same error. When i ran xcode-select -p, it gave output as /Library/Developer/CommandLineTools. So that means xcode was already installed in my system. Then i ran steps as given on this answer. After which any command which required xcode ran successfully.

Unable to get MacPort functionality after installing Xcode 4.3

I am having trouble getting MacPorts to function properly. I just installed OSX Lion 10.7.3 I downloaded and installed MacPorts first, and then after reading the requirements, I downloaded Xcode4.3 from the App Store, and then installed it. I launched Xcode and it looks to be operational and functional. However when I attempted to port with MacPorts, it gave me this error message(excerpt):
Warning: xcodebuild exists but failed to execute
Warning: Xcode does not appear to be installed; most ports will likely fail to build.
I followed the advice from:
How do i install additional packages for Xcode on OSX Lion to allow MacPorts to work
and installed command_line_tools_for_xcode from the Preferences within Xcode. I closed Xcode, and again got the errors:
$ sudo port install libsocketsPassword:
Warning: xcodebuild exists but failed to execute
Warning: Xcode does not appear to be installed; most ports will likely fail to build.
---> Computing dependencies for libsockets
---> Dependencies to be installed: openssl zlib
---> Extracting zlib
Error: Couldn't determine your Xcode version (from '/usr/bin/xcodebuild -version').
Error:
Error: If you have not installed Xcode, install it now; see:
Error: http://guide.macports.org/chunked/installing.xcode.html
Error:
Error: Target org.macports.extract returned: unable to find Xcode
Error: Failed to install zlib
Log for zlib is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_tarballs_ports_archivers_zlib/zlib/main.log
Error: The following dependencies were not installed: openssl zlib
Error: Status 1 encountered during processing.
I am uncertain where to go next with this. How do i trouble shoot my Xcode and MacPort interface?
In theory this should work if you have Xcode4.3 installed (in /Applications):
$ sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/
(And you've installed the optional command line tools)
Everything will start working fine after installation of "Command Line Tools for Xcode" package.
You can get it from here: https://developer.apple.com/downloads/index.action#
Please see the MacPorts migration instructions for Xcode 4.3.
The instructions are pretty involved. You need to run xcode-select to set a new tools path, update developer_dir in macports.conf (as described by Henk Poley), re-install MacPorts (ouch), and finally uninstall and re-install all of your ports (double ouch).
Edit: libpvx still wouldn't install after the above. Two extra steps were required:
sudo ln -s /Developer /
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs /SDKs
YMMV if you have different ports installed!
Also in /opt/local/etc/macports/macports.conf change the line with developer_dir to point to / instead of /Developer.
After
sudo xcode-select -switch /Applications/Xcode.app
I also had to run
sudo xcodebuild -license
and accept the licence
Here is a solution that has worked for me:
Install Command Line Tools for Xcode
Xcode -> Preferences -> Downloads
Help MacPorts find the right Xcode folder
sudo /usr/bin/xcode-select -switch /Applications/Xcode.app
Create symbolic links for clang compilers as they now live elsewhere
sudo ln -s `which clang` /Applications/Xcode.app/Contents/Developer/usr/bin/
sudo ln -s `which clang++` /Applications/Xcode.app/Contents/Developer/usr/bin/
Try using trunk, there's no release supporting Xcode 4.3 yet.
Setting the developer path in /opt/local/etc/macports.conf works for me,
developer_dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
since most of the compilers are stored there now instead of /usr/bin under Developer.
None of this works for me. Wait for macports to release a new version that officially supports XCode 4.3+
sudo mv /usr/bin/xcodebuild /usr/bin/xcodebuild.old
sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild /usr/bin/xcodebuild
Starting with Xcode 4.3, the command-line build tools are not installed by default. Launch Xcode, open the Preferences, and go to the Downloads tab. From there you should have an option to install the command-line tools.
You can also download them from the web here: https://developer.apple.com/downloads/index.action
Disclaimer: I haven't installed Xcode 4.3 yet. I have only read about it on the web.
As of 27/2/2012, the official suggestion from MacPorts seems to be to not use XCode 4.3 and instead use 4.1 through 4.2.1, which can be downloaded from Apple.
There is a bug ticket which might be useful to follow the evolution of this.
Incidentally, and as reported in my comment #11 in that bug report, I am able to build ports without warnings by using the 2 most sane-looking suggestions found in this question: sudo /usr/bin/xcode-select -switch /Applications/Xcode.app/Contents/Developer and changing developer_dir in /opt/local/etc/macports/macports.conf to /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
I have macports installed without admin/root privileges, so I was unable to test the xcode-select answers. However, I observed that Pall Melsted's answer worked, but not initially. What I found out was that I had not accepted the Xcode 4.5 license agreement!
If you have just installed Xcode for the purposes of macports, and you haven't accepted the Xcode license yet, you might get the error presented by the original post. When I checked my Xcode version using /usr/bin/xcodebuild -version, I was given the prompt to read and accept the license. After doing so, and after having made the changes suggested by Pall to the macports.conf developer_dir, it all works now.
As alternative: you can make downgrade of Xcode to 4.2.1 version. DMG of Xcode 4.2.1 placed here: https://developer.apple.com/downloads/index.action
After this MacPorts became works fine for me.
This is fixed in MacPorts 2.0.4.
To upgrade:
Download MacPorts 2.0.4 from the install site or run sudo port selfupdate.
Run the MacPorts migration described here to reinstall all ports. This is painful but required to get back to a working state.
You should definitely run sudo xcode-select -switch /Applications/Xcode.app like everyone here says, that'll fix many problems, but certainly not all.
Afaik, all the remaining problems exist within the configuration information for various packages. You might simply reinstall MacPorts as described in the migration instructions, but I found another solution.
You should begin finding all effected port files using commands like grep /Developer/ ..., after executing sudo bash and cd /opt/local naturally.
You should identify all effected ports by using port provides ..., which I piped through sed and sort | uniq. You could simply reinstall all these ports using either port -n upgrade --force ... or separate port uninstall ... and port install ... commands.
I recommend using one large port -n upgrade --force ... command to avoid duplicate rebuilds of dependencies, using the separate uninstall and install commands afterwards.
There are of course various ports for which /Developer exists only inside text config files, meaning you can fix them manually with sed -i -e 's/\/Developer//g' ..., but you cannot do so with binaries obviously.
I'm afraid you must at minimum rebuild all your Python and Perl installations, making this upgrade an ideal time to clean out packages that depend upon older versions, ala python26 and perl5.8.
There are several technically effected ports I decided against rebuilding like fuse4x-kext, who contained /Developer inside Library/Extensions/fuse4x.kext/Contents/MacOS/fuse4x but hasn't prevented sshfs from working correctly.
I had initially installed xcode 3.2.2, after which I installed 4.3. When I ran the xcode-select, I still got the same error about no xcode project in /Applications. I then dug into the /usr/bin/xcodebuild script and found out that this was working correctly, and another instance of xcodebuild (the one installed with xcode 4.3, not the one in /usr/bin) was being run and returning the error:
xcodebuild: error: The directory /Applications does not contain an Xcode project.
It seems the /usr/bin/xcode-select does not work for xcode 4.3, (it's compiled so you can't really see why it's not working). Strings doesn't give any clues. Good thing osx has strace.. oh wait.
Anyways, the best I could do was modify /opt/local/etc/macports.conf
and uncomment the line containing the path to the xcode installation. That seems to fix my problem for the most part.

Resources