当我在终端中运行brew时,我得到一个错误:

 /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>'

这些是我的宝石设置:

- 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

当前回答

要恢复您的Homebrew设置,请尝试以下操作:

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

其他回答

首先,打开一个终端会话并运行:

cd /usr/local/
git status

看看家酿啤酒是否干净

如果是脏的,运行:

git reset --hard && git clean -df

then

brew doctor
brew update

如果它还是坏了,在你的疗程中试试这个:

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

这将迫使Homebrew在系统安装时使用Ruby 1.8。

这个问题应该在最新版本的Homebrew中得到解决。尝试重新安装它,Homebrew主页上有描述。

在我看来,popen是一个C系统库,它的头文件丢失了。

检查您是否已经成功地使用命令行工具安装了xcode,并接受了许可证。

如何安装Xcode命令行工具

卸载自制程序:

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

然后重新安装

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

警告:此脚本将删除:/Library/Caches/Homebrew/ -谢谢benjaminsila

原来的答案

该问题主要发生在OS X更新到El Capitan (OS X 10.11)或macOS Sierra (macOS 10.12)后。

这是因为El Capitan或后续macOS的新SIP进程存在文件权限问题。尝试更改/usr/local目录的权限:

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

如果它仍然不工作,在终端会话中使用这些步骤,一切都会好起来:

cd /usr/local/Homebrew
git reset --hard origin/master
brew update

如果/usr/local/Library/Homebrew不能工作,请尝试/usr/local/ home brew问题可能是Homebrew已经过时了。

2021年4月更新

如上所述,上述命令不适用于macOS High Sierra或以上版本。你必须运行这个:

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