ChatGPT解决这个技术问题 Extra ChatGPT

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

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
Can you add information? What command did you exactly run?
i just typed "brew"into unix
What happens when you run brew doctor ?
same error. here are my env gem settings
Looks like your ruby installation is incomplete. Try reinstalling or using another ruby installation.

C
Chuck Le Butt

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)/*

I had the problem caused by El Capitan update. This solved the problem. Thanks.
Same here, upgrade to El Capitan broke it, I had to reset the permissions first and then run the git commands and brew update worked. Thanks.
This is right answer if you are facing that problem after upgrading to El Capitan :)
Had this issue after upgrading to macOS Sierra. This solved it, thanks! Though, changing permissions on /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"
Second method worked for me. I just needed to find where HOMEBREW directory was located. In my case: /usr/local/Library/Homebrew
t
the Tin Man

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.


Probably a good answer, but BTW I get other errors when running both commands give (I mention incase anyone wants to cover this further scenario): - rm: /System/Library/Frameworks/Ruby.framework/Versions/Current: Operation not permitted
I simply reinstalled homebrew with a fresh version and it started working. Check homebrew homepage with the link to install, and when you try it it will complain that homebrew is already installed and teach you how to uninstall.
So, uninstalling/reinstalling got Homebrew working again for me. It also deleted everything it had installed, basically trashing my system. So not a great solution.
If you're getting errors with ruby and you're using RVM, try issuing rvm use system to ensure you're using Mac OS X's ruby when running brew update
Note that the default Ruby on recent versions of OS X is 2.0, not 1.8.
C
Community

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


I run an uninstall of Homebrew and then a reinstall. Fixed the issue. @OsTa ruby -e "$(curl -fsSL raw.githubusercontent.com/Homebrew/install/master/uninstall)" Warning: This script will remove: /Library/Caches/Homebrew/
Sort of a shotgun approach but this worked more easily than trying to manage file permissions...
Worked for me On a system upgraded to 10.12 (Sierra), after the uninstall/reinstall I was able to run 'brew doctor' and followed the instructions there to fix a few permissions issues. Working fine now
After a hard drive crash my underlying git repository was corrupted and while git reset would therefore not work, un-/reinstalling did. However, I had to reinstall all my installed packages.
I
Inanc Gumus

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)"

In case you get stuck after this in brew install / uninstall loop, use following link - github.com/Homebrew/homebrew/issues/44460
Did you get this meesage trying the 2nd command (which seems to be an indication something has gone wrong, though not an error)? - The current contents of /usr/local are bin Cellar CODEOFCONDUCT.md CONTRIBUTING.md etc Frameworks git include lib Library LICENSE.txt opt Qt4.7 README.md share SUPPORTERS.md var .git .gitignore
@PandaWood no, i didn't. what the content of the error message that you depicting with 'this message' in your comment?
@deeperx Everything after the "-". In the end, I had to uninstall brew and reinstall again
@PandaWood Do you use correct commas? Can you copy paste it here directly?
t
the Tin Man

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.


isn't it quite dangerous?
Permissions to /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.
t
the Tin Man

First I executed:

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

Then:

cd $(brew --prefix) && git fetch origin && git reset --hard origin/master

FYI, my Homebrew install was at /usr/local/Homebrew/ so I had to use cd $(brew --prefix)/Homebrew.
t
the Tin Man

This issue should be fixed in the newest version of Homebrew. Try reinstalling it, which is described on the Homebrew home page.


D
Dennis

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


t
the Tin Man

To restore your Homebrew setup try this:

cd /usr/local/Homebrew/Library && git stash && git clean -d -f && git reset --hard && git pull

关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now