如何在 El Capitan 上重新安装 brew?

How to reinstall brew on El Capitan?

我不得不在 El Capitan 上重新安装 brew,ruby。

实际上我不记得它到底是怎么发生的,但我丢失了我的 brew,我没有重新安装它。

这是我尝试重新安装时收到的消息:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
<internal:gem_prelude>:1:in `require': cannot load such file -- rubygems.rb (LoadError)
from <internal:gem_prelude>:1:in `<compiled>'

首先,一些信息:

>which ruby
/usr/local/bin/ruby

>ruby --version
ruby 2.2.1p85 (2015-02-26 revision 49769) [x86_64-darwin12.6.0]

而且,如果我尝试修复 ruby:

>rvm list known
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p643]
[ruby-]2.1.4
[ruby-]2.1[.5]
[ruby-]2.2[.1]
[ruby-]2.2-head
ruby-head

>rvm install 2.2
Searching for binary rubies, this might take some time.
Found remote file https://rvm_io.global.ssl.fastly.net/binaries/osx/10.11/x86_64/ruby-2.2.1.tar.bz2
Checking requirements for osx.
About to install Homebrew, press `Enter` for default installation in `/usr/local`,
type new path if you wish custom Homebrew installation (the path needs to be writable for user)
: 
<internal:gem_prelude>:1:in `require': cannot load such file -- rubygems.rb (LoadError)
    from <internal:gem_prelude>:1:in `<compiled>'
Requirements installation failed with status: 1.

现在如何进行?

我发现了问题。

我 运行 type -a ruby 看到我安装了两个 ruby:一个在 /usr/bin 上,另一个在 /usr/local/bin

我只是mv /usr/local/bin/ruby /usr/local/bin/rubybkp并解决了问题

之后我 运行 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 重新安装 brew。

此外,请注意现在安装 brew 使用 Bash:

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

Warning: The Ruby Homebrew installer is now deprecated and has been rewritten in Bash. 
Please migrate to the following command:
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"