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
brew doctor
?
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)/*
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.
rvm use system
to ensure you're using Mac OS X's ruby when running brew update
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
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)"
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.
/usr/local
were changed in the OS for security reasons - so, just because you've "returned rights as before" doesn't mean it's a good thing to do.
First I executed:
sudo chown -R $(whoami):admin /usr/local
Then:
cd $(brew --prefix) && git fetch origin && git reset --hard origin/master
/usr/local/Homebrew/
so I had to use cd $(brew --prefix)/Homebrew
.
This issue should be fixed in the newest version of Homebrew. Try reinstalling it, which is described on the Homebrew home page.
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: How to install Xcode Command Line Tools
To restore your Homebrew setup try this:
cd /usr/local/Homebrew/Library && git stash && git clean -d -f && git reset --hard && git pull
Success story sharing
/usr/local
doesn't seem to be required now. "Homebrew no longer needs to have ownership of /usr/local. If you wish you can return/usr/local
to its default ownership with:sudo chown root:wheel /usr/local
"HOMEBREW
directory was located. In my case:/usr/local/Library/Homebrew