Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Can't install anything and brew doctor just hangs #25167

Closed
PacoH opened this issue Dec 12, 2013 · 31 comments
Closed

Can't install anything and brew doctor just hangs #25167

PacoH opened this issue Dec 12, 2013 · 31 comments

Comments

@PacoH
Copy link

PacoH commented Dec 12, 2013

I've only had Homebrew installed a short time and this is the second time this has happened. I try to install something, in this case gd, and absolutely nothing happens. Brew just hangs and has to be force terminated (ctrl-c). 'brew doctor' does the same thing and has to be force terminated. So there is no way for me to diagnose the install problem. It seems to me that if anything should run, it is the doctor. I successfully Updated Homebrew from ccf3d099 to 87172bd with no improvement.

brew --config gives:

HOMEBREW_VERSION: 0.9.5
ORIGIN: https://github.com/mxcl/homebrew
HEAD: 87172bd
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: 16-core 64-bit arrandale
OS X: 10.8.5-x86_64

This command hangs too BTW.

The last time this happened, I found a thread that implied that permissions were the problem so I manually changed permissions and ownership and rebooted and that solved it. This time permissions and ownership seem to be in order:

~ : user$ ls -l /usr/local
total 64
-rw-r--r-- 1 user admin 493 Dec 6 12:14 CONTRIBUTING.md
drwxrwxr-x 23 user admin 782 Dec 6 12:37 Cellar
drwxr-xr-x 9 user admin 306 Dec 2 13:06 Library
-rw-r--r-- 1 user admin 928 Dec 6 12:14 README.md
-rw-r--r-- 1 user admin 23510 Dec 6 12:14 SUPPORTERS.md
drwxrwxr-x 725 user admin 24650 Dec 6 12:39 bin
drwxr-xr-x 8 user staff 272 Sep 20 08:34 clamXav
drwxr-xr-x 5 user admin 170 Dec 6 12:34 etc
drwxrwxr-x 40 user admin 1360 Dec 6 12:39 include
drwxrwxr-x 105 user admin 3570 Dec 6 12:39 lib
drwxr-xr-x 23 user admin 782 Dec 6 12:39 opt
drwxrwxr-x 17 user admin 578 Dec 6 12:34 share

I tried rebooting but this time it didn't help.

None of the threads I have read really address this problem in my case. I have no idea how to procede from here. Homebrew is supposed to make installation from the command line easy. Instead it has been a nightmare for me. I really don't want to re-install everything each time this happens, nor do I want to install macports, so I want to learn exactly how to troubleshoot the problem and fix it. It looks like this will be a perpetual problem. Any help from someone who has solved this problem would be greatly appreciated. It seems that there are enough people having this problem that a sticky should be created about dealing with it.

@mistydemeo
Copy link
Member

Can you show the output of xcode-select -print-path? I suspect this is due to a bug that exists in Apple's xcrun tool on 10.7 and 10.8.

@mistydemeo
Copy link
Member

To be specific, you probably at some point ran xcode-select -switch /. That triggers an endless loop in Apple's xcrun tool.

If you have Xcode, you need to xcode-select -switch /Applications/Xcode.app, or wherever Xcode is installed. If you only have the CLT, you need to unset the path. xcode-select doesn't provide a way to do that, but you can sudo rm -rf /usr/share/xcode-select.

@PacoH
Copy link
Author

PacoH commented Dec 13, 2013

user$ xcode-select -print-path

xcode-select: Error: No Xcode is selected. Use xcode-select -switch , or see the xcode-select manpage (man xcode-select) for further information.

I installed only CLT. I tried sudo rm -rf /usr/share/xcode-select but there is no /usr/share/xcode-select and this didn't work. I've never run xcode-select -switch / before.

@mistydemeo
Copy link
Member

Can you test running a tool via xcrun outside of homebrew to see if it works? For example, xcrun git --version.

@PacoH
Copy link
Author

PacoH commented Dec 13, 2013

xcrun git --version xcode-select: Error: No Xcode is selected. Use xcode-select -switch <path-to-xcode>, or see the xcode-select manpage (man xcode-select) for further information.

@PacoH
Copy link
Author

PacoH commented Dec 13, 2013

Even with brew doctor hanging, I see ruby at 0% CPU and don't see xcrun at all.

I did:
sudo xcode-select -switch /usr/bin
xcode-select -print-path /usr/bin

But xcrun still doesn't run.

@PacoH
Copy link
Author

PacoH commented Dec 13, 2013

Here's a thought. I installed perlbrew shortly before I noticed the problem. I don't see why that would conflict but maybe…

@PacoH
Copy link
Author

PacoH commented Dec 13, 2013

which xcrun /usr/bin/xcrun

echo $PATH /Users/user/perl5/perlbrew/bin:/Users/user/perl5/perlbrew/perls/perl-5.18.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/opt/ImageMagick/bin

@PacoH PacoH closed this as completed Dec 13, 2013
@PacoH
Copy link
Author

PacoH commented Dec 13, 2013

OK, I found this thread about problems with the ever-maddening mdfind:

http://stackoverflow.com/questions/16546722/why-is-brew-doctor-stalling-on-mdfind

I ran brew doctor and in another window ran killall mdfind 4 times before brew doctor terminated successfully. But if I run brew doctor again, I have to kill mdfind 4 more times, so this reveals the problem but does not fix it.

@PacoH
Copy link
Author

PacoH commented Dec 13, 2013

OK, I was able to install gd by killing mdfind 4 times as above. This works but is obviously not a solution. Others have had this problem but how do you solve it permanently?

@MikeMcQuaid
Copy link
Member

Do you have Spotlight disabled?

@PacoH PacoH reopened this Dec 13, 2013
@PacoH
Copy link
Author

PacoH commented Dec 13, 2013

No. I assume the reason mdfind is running like that is because Spotlight is enabled. You have to enable it to be able to search even a local directory in Finder. It is so stupid, it can only search its precious corruptible database and not the directory directly so I need to have it enabled. I think the fact that it interferes with brew like it does should be considered a bug. It doesn't do this when I run perlbrew or perl cpanm.

@MikeMcQuaid
Copy link
Member

We could/should perhaps make our mdfind calls timeout. That said, if mdfind isn't working then parts of Homebrew will have problems.

@MikeMcQuaid
Copy link
Member

We may implement a timeout at some stage. Please use a politer tone; we're trying to help and we're doing this in our free time.

@PacoH PacoH closed this as completed Dec 13, 2013
@PacoH
Copy link
Author

PacoH commented Dec 13, 2013

if mdfind isn't working then parts of Homebrew will have problems

Can you explain? Does this mean that killing mdfind has possibly caused a bad install in my case?

@MikeMcQuaid
Copy link
Member

No, it won't damage anything. If mdfind hangs in normal operation that just means that when Homebrew tries to call it it'll hang then too. It's used to lookup e.g. Xcode and other locations (and also internally by some Xcode tools such as (iirc) xcrun).

@PacoH PacoH reopened this Dec 14, 2013
@PacoH
Copy link
Author

PacoH commented Dec 14, 2013

No, mdfind does not hang in normal operation. I don't even see it in the Activity Monitor except when I run brew doctor or brew install. In fact, I'm doing a system-wide search right now using Spotlight and it's grinding away but mdfind is nowhere to be seen in Activity Monitor or top. I do see mdworker, mdwrite, and mds running. Maybe that is the problem.

@mistydemeo
Copy link
Member

Can you test some of the mdfind invocations that Homebrew uses?

/usr/bin/mdfind "kMDItemCFBundleIdentifier == 'com.apple.dt.Xcode'"
/usr/bin/mdfind "kMDItemCFBundleIdentifier == 'com.apple.Xcode'"
/usr/bin/mdfind "kMDItemCFBundleIdentifier == 'org.macosforge.xquartz.X11'"
/usr/bin/mdfind "kMDItemCFBundleIdentifier == 'org.x.X11'"

@chdiza
Copy link
Contributor

chdiza commented Dec 15, 2013

I didn't realize that Homebrew used mdfind at all. I have indexing disabled via mdutil (and have always had it thus), and have never run into any issue like this. I ran the mdfind commands listed above and got no output. I hope this is not silently doing something bad to my brew installation.

@avetisk
Copy link

avetisk commented Dec 25, 2013

Would be awesome to just avoid using mdfind (if possible).

(and yes, I have disabled Spotlight).

@MikeMcQuaid
Copy link
Member

If you submit a pull request we'll consider it.

@jacknagel
Copy link
Contributor

mdfind is used to determine the XQuartz version because it is the fastest, most reliable way to do so. If Spotlight is disabled (i.e. mdfind fails) then we fall back to pkgutil, but this is much, much slower, so it is not the default.

It is also used as one of several fallbacks for locating Xcode on systems where it is not in the normal location. I don't think this code path is ever hit on recent-ish OS X/Xcode versions though.

In other words, Homebrew will continue to function if you have Spotlight turned off, but we can't stop using it unless someone can prove there is another way to get the information we need that does not negatively impact performance and is portable across OS X versions.

@avetisk
Copy link

avetisk commented Dec 26, 2013

I see. Then I guess I'll have to keep Spotlight turned on.

It is also used as one of several fallbacks for locating Xcode on systems where it is not in the normal location. I don't think this code path is ever hit on recent-ish OS X/Xcode versions though.

Actually, I have the latest version of Xcode and running on Mavericks (up-to-date).

@jacknagel
Copy link
Contributor

Actually, I have the latest version of Xcode and running on Mavericks (up-to-date).

Right, what I mean is that under 10.8/10.9 and Xcode 5, the mdfind fallback for locating Xcode is never reached. It is still used for XQuartz though.

@avetisk
Copy link

avetisk commented Dec 26, 2013

Sorry, I overlooked your previous message. I guess that's why I got the error messages.

And I suppose that piping locate with some appropriated greps would be x2/x3 slower than mdfind.

@jacknagel
Copy link
Contributor

Basically any replacement has to be able to emulate not only mdfind but also mdls:

mdls -raw -nullMarker "" -name kMDItemVersion "/Applications/Utilities/XQuartz.app" 2>/dev/null
2.7.5

I don't think there is a viable alternative.

@avetisk
Copy link

avetisk commented Dec 26, 2013

grep -A1 'VersionString</key>' "/Applications/Utilities/XQuartz.app/Contents/Info.plist" | egrep -o '(\d+\.?)+'

If the trailing EOL is an issue, you can add | xargs echo -n.

This works pretty fast.

@jacknagel
Copy link
Contributor

I'm not going to replace the existing implementation, which has been refined and battle-tested over the course of two years to provide consistent results under as many OS X configurations as possible, with a series of calls to grep though a plist file unless it is actually fixing a reproducible bug.

If you just don't want to have Spotlight enabled, that's fine, Homebrew already has fallbacks in place to cope with that.

If mdfind is hanging, then we should figure out why, and how to fix it. But replacing code in Homebrew that works for 99.9% of users is not an acceptable way to go about that.

@avetisk
Copy link

avetisk commented Dec 26, 2013

Well, I was just answering to:

I don't think there is a viable alternative.

And as I said before:

I see. Then I guess I'll have to keep Spotlight turned on.

And so did I.

@PacoH
Copy link
Author

PacoH commented Feb 10, 2014

Solution

Here's an update. I finally solved the problem. At the risk of being accused of cross-posting, I think it bears repeating here since I started this thread. I posted this solution at brew doctor hangs at mdfind.

I ran all the checks recommended in the posts and found multiple checks that caused brew doctor to hang. Note that killing mdfind multiple times at least allows brew doctor to continue but that is not a solution.

When brew doctor finally completed, I noticed one warning:

check_user_path_2
Warning: Homebrew's bin was not found in your PATH.
Consider setting the PATH for example like so
    echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile

This added export PATH=/usr/local/bin:$PATH to ~/.bash_profile.
This was also at the beginning of ~/.bash_profile and twice at the end so I deleted all but the last statement. Opening a new terminal window, now /usr/local/bin is at the beginning of my path instead of in the middle.

Now brew doctor runs without hanging!

@jbinto
Copy link

jbinto commented Oct 7, 2014

Thanks @PacoH, your solution fixed the same issue for me (brew update and brew doctor hanging).

@Homebrew Homebrew locked and limited conversation to collaborators Feb 17, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants