How to avoid "cannot load such file -- utils/popen" from homebrew on OSX How to avoid "cannot load such file -- utils/popen" from homebrew on OSX ruby ruby

How to avoid "cannot load such file -- utils/popen" from homebrew on OSX


Original Answer

The problem mainly occurs after updating OS X to El Capitan (OS X 10.11) or macOS Sierra (macOS 10.12).

This is because of file permission issues with El Capitan’s or later macOS's new SIP process. Try changing the permissions for the /usr/local directory:

$ sudo chown -R $(whoami):admin /usr/local  

If it still doesn't work, use these steps inside a terminal session and everything will be fine:

cd /usr/local/Library/Homebrewgit reset --hardgit clean -dfbrew update

If /usr/local/Library/Homebrew doesn't work, try /usr/local/Homebrew. The problem might be that Homebrew is outdated.

Apr 2021 Update

The command above doesn't work for macOS High Sierra or above, as explained in this GitHub issue. You have to run this instead:

sudo chown -R $(whoami) $(brew --prefix)/*


First, open a terminal session and run:

cd /usr/local/git status

to see if Homebrew is clean.

If it's dirty, run:

git reset --hard && git clean -df

then

brew doctorbrew update

If it's still broken, try this in your session:

sudo rm /System/Library/Frameworks/Ruby.framework/Versions/Currentsudo ln -s /System/Library/Frameworks/Ruby.framework/Versions/1.8 /System/Library/Frameworks/Ruby.framework/Versions/Current

This will force Homebrew to use Ruby 1.8 from the system's installation.


Uninstall homebrew:

 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

Then reinstall

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Warning: This script will remove: /Library/Caches/Homebrew/ - thks benjaminsila