How to avoid "cannot load such file -- utils/popen" from homebrew on OSX
RubyMacosRubygemsHomebrewRuby Problem Overview
I'm getting an error when I run brew
in the terminal:
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- utils/popen (LoadError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/Library/Homebrew/utils.rb:6:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/Library/Homebrew/global.rb:9:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/Library/brew.rb:16:in `<main>'
These are my gem settings:
- RUBYGEMS VERSION: 2.0.14
- RUBY VERSION: 2.0.0 (2014-02-24 patchlevel 451) [universal.x86_64-darwin13]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.0.0
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-13
- GEM PATHS:
- /Library/Ruby/Gems/2.0.0
- /Users/ronaldkwan/.gem/ruby/2.0.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
Ruby Solutions
Solution 1 - Ruby
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/Homebrew
git reset --hard origin/master
brew 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)/*
Solution 2 - Ruby
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 doctor
brew update
If it's still broken, try this in your session:
sudo rm /System/Library/Frameworks/Ruby.framework/Versions/Current
sudo 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.
Solution 3 - Ruby
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
Solution 4 - Ruby
In my case I just needed to remove Homebrew's executable using:
sudo rm -f `which brew`
Then reinstall Homebrew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Solution 5 - Ruby
After updating to El Capitan, /usr/local
has root:wheel
rights.
Change the rights back to the user using:
sudo chown -R $(whoami):admin /usr/local
and:
brew doctor && brew update
This helped me to get Homebrew working again.
Solution 6 - Ruby
First I executed:
sudo chown -R $(whoami):admin /usr/local
Then:
cd $(brew --prefix) && git fetch origin && git reset --hard origin/master
Solution 7 - Ruby
This issue should be fixed in the newest version of Homebrew. Try reinstalling it, which is described on the Homebrew home page.
Solution 8 - Ruby
To me it feels like you have missing header files for popen, which is a C system library.
Check if you have installed xcode successful with the command line tools and have accepted the license.
See this thread for more information: https://stackoverflow.com/questions/9329243/xcode-install-command-line-tools
Solution 9 - Ruby
To restore your Homebrew setup try this:
cd /usr/local/Homebrew/Library && git stash && git clean -d -f && git reset --hard && git pull