Ruby on rails Rbenv:无法安装2.2.0或2.2.1。无法在2.2.2(OSX 10.10.4)上安装“gem-install bundler”

Ruby on rails Rbenv:无法安装2.2.0或2.2.1。无法在2.2.2(OSX 10.10.4)上安装“gem-install bundler”,ruby-on-rails,ruby,macos,bundler,rbenv,Ruby On Rails,Ruby,Macos,Bundler,Rbenv,在我试图为另一个问题找到解决方案的过程中,我遇到了挫折,只是用rm-rf~/.rbenv/versions/2.2.2删除了我的Ruby安装。使用rbenv install 2.2.2重新安装时,我突然发现无法安装bundlergem。gem install bundler命令导致以下错误: ERROR: Loading command: install (LoadError) cannot load such file -- zlib ERROR: While executing

在我试图为另一个问题找到解决方案的过程中,我遇到了挫折,只是用
rm-rf~/.rbenv/versions/2.2.2
删除了我的Ruby安装。使用
rbenv install 2.2.2重新安装时,我突然发现无法安装
bundler
gem。
gem install bundler
命令导致以下错误:

ERROR:  Loading command: install (LoadError)
    cannot load such file -- zlib
ERROR:  While executing gem ... (NoMethodError)
    undefined method `invoke_with_build_args' for nil:NilClass
我所读到的一切似乎都表明,缺少
zlib
包通常是Linux系统的一个问题。然而,我使用的是OSX 10.10.4,我已经读到
zlib
应该与命令行工具一起提供,我有

在谷歌搜索了一段时间后,没有任何进展,我决定用rbenv重新开始。我卸载了rbenv并重新安装了它,但我仍然无法在ruby 2.2.2的rbenv安装中安装bundler。此外,我发现我根本无法安装版本2.2.0或2.2.1:

MacBook-Pro:~ me$ rbenv install 2.2.0
Downloading ruby-2.2.0.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/7671e394abfb5d262fbcd3b27a71bf78737c7e9347fa21c39e58b0bb9c4840fc
Installing ruby-2.2.0...

BUILD FAILED (OS X 10.10.4 using ruby-build 20150519)

Inspect or clean up the working tree at /var/folders/rm/38vbv5g952s54r1txrmrdlf40000gn/T/ruby-build.20150705212307.49958
Results logged to /var/folders/rm/38vbv5g952s54r1txrmrdlf40000gn/T/ruby-build.20150705212307.49958.log

Last 10 log lines:
    from /private/var/folders/rm/38vbv5g952s54r1txrmrdlf40000gn/T/ruby-build.20150705212307.49958/ruby-2.2.0/lib/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /private/var/folders/rm/38vbv5g952s54r1txrmrdlf40000gn/T/ruby-build.20150705212307.49958/ruby-2.2.0/lib/rubygems.rb:556:in `install'
    from ./tool/rbinstall.rb:717:in `block (2 levels) in <main>'
    from ./tool/rbinstall.rb:716:in `each'
    from ./tool/rbinstall.rb:716:in `block in <main>'
    from ./tool/rbinstall.rb:749:in `call'
    from ./tool/rbinstall.rb:749:in `block in <main>'
    from ./tool/rbinstall.rb:746:in `each'
    from ./tool/rbinstall.rb:746:in `<main>'
make: *** [do-install-all] Error 1 
事实证明,要么a)我的Xcode安装出了问题(不确定会发生什么/如何发生),要么b)升级OSX后需要手动更新Xcode


尽管我升级了命令行工具,但我还是决定在应用商店中检查我的Xcode安装,并注意到可以安装/更新。所以我这么做了,然后一切都很顺利

你也在使用自制软件吗?如果可以,请尝试运行
brew doctor
。感谢@MattBrictson的评论。是的,我一直在使用自制软件安装/卸载rbenv和ruby build。我在运行
brew doctor
时收到一些警告,但它看起来不像我以前见过的任何东西。我将把完整的输出添加到我的帖子中。嗯,我以前没有看到那些
brew医生
警告。也许可以尝试将
libz*
文件移出
/usr/local/lib
,看看这是否解决了问题?事实证明这与我的Xcode安装有关。我已经把答案贴在下面了
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry and just ignore them. Thanks!

Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected dylibs:
    /usr/local/lib/libatk-1.0.0.2209.1.dylib
    /usr/local/lib/libgdk-x11-2.0.0.1200.0.dylib
    /usr/local/lib/libgdk_pixbuf-2.0.0.1200.0.dylib
    /usr/local/lib/libgdk_pixbuf_xlib-2.0.0.1200.0.dylib
    /usr/local/lib/libgio-2.0.0.0.0.dylib
    /usr/local/lib/libGLEW.1.5.4.dylib
    /usr/local/lib/libglib-2.0.0.1600.0.dylib
    /usr/local/lib/libgmodule-2.0.0.1600.0.dylib
    /usr/local/lib/libgobject-2.0.0.1600.0.dylib
    /usr/local/lib/libgthread-2.0.0.1600.0.dylib
    /usr/local/lib/libgtk-x11-2.0.0.1200.0.dylib
    /usr/local/lib/libintl.8.0.2.dylib
    /usr/local/lib/libjpeg.62.dylib
    /usr/local/lib/libpango-1.0.0.2100.0.dylib
    /usr/local/lib/libpangocairo-1.0.0.2100.0.dylib
    /usr/local/lib/libpangoft2-1.0.0.2100.0.dylib
    /usr/local/lib/libpangox-1.0.0.2100.0.dylib
    /usr/local/lib/libpangoxft-1.0.0.2100.0.dylib
    /usr/local/lib/libportaudio.2.0.0.dylib
    /usr/local/lib/libSDL-1.2.0.dylib
    /usr/local/lib/libz.1.2.5.dylib

Warning: Unbrewed .la files were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected .la files:
    /usr/local/lib/libatk-1.0.la
    /usr/local/lib/libgdk-x11-2.0.la
    /usr/local/lib/libgdk_pixbuf-2.0.la
    /usr/local/lib/libgdk_pixbuf_xlib-2.0.la
    /usr/local/lib/libgio-2.0.la
    /usr/local/lib/libglib-2.0.la
    /usr/local/lib/libgmodule-2.0.la
    /usr/local/lib/libgobject-2.0.la
    /usr/local/lib/libgthread-2.0.la
    /usr/local/lib/libgtk-x11-2.0.la
    /usr/local/lib/libintl.la
    /usr/local/lib/libjpeg.la
    /usr/local/lib/libpango-1.0.la
    /usr/local/lib/libpangocairo-1.0.la
    /usr/local/lib/libpangoft2-1.0.la
    /usr/local/lib/libpangox-1.0.la
    /usr/local/lib/libpangoxft-1.0.la
    /usr/local/lib/libportaudio.la

Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected static libraries:
    /usr/local/lib/libintl.a
    /usr/local/lib/libjpeg.a
    /usr/local/lib/libportaudio.a
    /usr/local/lib/libz.a