在OS X Mavericks上降级Ruby出现问题

6

OS X 10.9自带ruby 2.0.0p195,但我需要安装Ruby 1.8.7。然而,我一直遇到错误。我已经安装了Xcode5-DP,并且我相信命令行工具也已经安装。

在终端中操作:

sudo rvm install 1.8.7
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10/x86_64/ruby-1.8.7-p371.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Installing requirements for osx, might require sudo password.
Certificates in '/usr/local/etc/openssl/cert.pem' already are up to date.
Installing Ruby from source to: /Users/alextoul/.rvm/rubies/ruby-1.8.7-p371, this may take a while depending on your cpu(s)...
ruby-1.8.7-p371 - #downloading ruby-1.8.7-p371, this may take a while depending on your connection...
ruby-1.8.7-p371 - #extracted to /Users/alextoul/.rvm/src/ruby-1.8.7-p371 (already extracted)
Patch stdout-rouge-fix was already applied.
Patch no_sslv2 was already applied.
ruby-1.8.7-p371 - #configuring...
Error running 'env CFLAGS=-O3 -I/usr/local/opt/libyaml/include -I/usr/local/opt/readline/include -I/usr/local/opt/libxml2/include -I/usr/local/opt/libxslt/include -I/usr/local/opt/libksba/include -I/usr/local/opt/openssl098/include LDFLAGS=-L/usr/local/opt/libyaml/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/libxml2/lib -L/usr/local/opt/libxslt/lib -L/usr/local/opt/libksba/lib -L/usr/local/opt/openssl098/lib ./configure --prefix=/Users/alextoul/.rvm/rubies/ruby-1.8.7-p371 --disable-install-doc --without-tcl --without-tk --enable-shared',
please read /Users/alextoul/.rvm/log/ruby-1.8.7-p371/1371228839_configure.log
There has been an error while running configure. Halting the installation.

1371228839_configure.log 的内容如下:

./configure
configure: WARNING: unrecognized options: --without-tcl, --without-tk
checking build system type... i686-apple-darwin13.0.0
checking host system type... i686-apple-darwin13.0.0
checking target system type... i686-apple-darwin13.0.0
checking whether the C compiler works... no
configure: error: in `/Users/alextoul/.rvm/src/ruby-1.8.7-p371':
configure: error: C compiler cannot create executables
See `config.log' for more details

其他(有用的)信息:

ruby -v
> ruby 2.0.0p195 (2013-05-14 revision 40734) [universal.x86_64-darwin13]
brew update
> Already up-to-date.
gcc --version
> Configured with: --prefix=/Applications/Xcode5-DP.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode5-DP.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/c++/4.2.1
> Apple LLVM version 5.0 (clang-500.1.58) (based on LLVM 3.3svn)
> Target: x86_64-apple-darwin13.0.0
> Thread model: posix
sudo rvm requirements
> Installing requirements for osx, might require sudo password.
> Certificates in '/usr/local/etc/openssl/cert.pem' already are up to date.

感谢您的帮助。

为RVM打开一个问题:https://github.com/wayneeseguin/rvm/issues - mpapis
5个回答

13

10.9是操作系统的早期测试版。[请注意本问题回答的日期为2013年7月]如果我正在运行10.9,我会假设我至少需要重新安装两次操作系统。(至少在测试期间需要一次,因为毕竟它是测试版,以及一次在10.9发布通用版本时,因为它还是测试版)。

考虑到这一点,我建议采取以下四种行动中的一种或多种:

  • 与RVM团队合作,深入了解10.9可能更改的编译器环境,并使Ruby 1.8.7编译。这更加棘手,因为技术上这些东西受到保密协议的管制。
  • 相反,设置一个虚拟机,在虚拟机上运行Ruby 1.8.7。使用Vagrant和Chef/Puppet获取额外积分,因为你甚至可能需要重构虚拟机。(只需将Vagrantfile和Puppet或Chef配置文件放在Github/Dropbox/whatever上,以便可以克隆它们并从头开始生成虚拟机。)
  • 或者仅需重启到10.8以完成生产工作。10.8是生产级别的操作系统,10.9应谨慎对待——它可能会吃掉你的工作。它确实不应该用于生产目的(即:日常编写Ruby代码)。如果你正在编写仅适用于10.9 Cocoa/Objective-C的应用程序(或更新RubyMotion之类的东西),那可能另当别论(但我仍然会保留好备份并小心对待它)。
  • 为升级到Ruby 2.0而努力更新您的代码库,因为Ruby 1.8.7已不再得到官方支持。

编辑(2013年10月24日): 如果您之所以来到这里是因为您刚安装了Mavericks(于2013年10月22日发布),想要在发布几天后让Ruby 1.8.7工作,并且RVM对您无效(因为您很不耐烦,等不了),那么您可以做以下操作(虽然我不是rbenv用户,但这应该有效):

  1. 使用Macports安装 port install ruby 。这是Ruby 1.8.7版本。在我的Mavericks机器上,这次编译可以正常运行(尽管您需要从源代码安装Macports并安装命令行开发人员工具,即使您已经安装了XCode 5. 是的,真的是这样)。
  2. 现在,安装rbenv
  3. ~/.rbenv/versions/ 文件夹中创建软链接 /opt/local/bin/ruby1.8 。特别是 ~ / .rbenv / versions / ruby-1.8.7-p374
  4. 阅读rbenv文档,但现在应该可以正常工作! (至少从文档上看是这样。再次说明,我不是rbenv用户,但在电视上扮演了一个)

我确信您也可以使用homebrew完成此操作,但是我知道最新的Macports可以正确安装Ruby 1.8.7,因为我使用的就是它(而且对我来说刚刚安装非常干净)。


1
如果可能的话,我会给答案中的每个点都点赞 ;) - mpapis
1
不妨试试rbenv,而非rvm,这是GitHub的人们所偏爱的,并且是他们的Boxen工具集所必需的,而rvm与之不兼容。我最近从rvm转换到rbenv,部分原因就在于此,它似乎至少能够同样地工作(尽管略有不同)。我还没有在Mavericks上尝试过它,所以我不知道它是否适用于这种情况,但值得一试。可以看看这些文章:http://www.overacker.me/blog/2013/07/10/getting-started-with-rbenv/和http://edapx.com/2013/05/23/switching-from-rvm-to-rbenv/。 - Joe Carroll
在单独运行并不是每个人的选择,也不是问题的解决方案。现在Maverick不再是“beta”版,这个无关答案就显露出了它最初的面目,一个无关答案。问题仍然存在,这个答案对此毫无作用。当然,我们应该努力更新我们的代码以符合2.0兼容性,但这是我们最好按自己的步伐来完成的事情。我期望在Expert Exchange上看到这样的回答,那里的人们为了得分而提供无用的回复。难道Stackoverflow正在变得更像Expert Exchange吗? - Beaon
1
现在 Mavericks 已经公开发布,人们可以在公共场合谈论它而不必担心 NDA。RVM 团队 - 例如 - 现在对 Mavericks 的问题非常敏感(只需查看他们的 Github 问题跟踪器)。您可能不应该降级系统 Ruby,而是使用 RVM/rbenv 安装一个单独的 Ruby 用于旧项目。如果 rvm 安装失败,请与 RVM/rbenv 开发人员合作以获取可用的 Ruby。实际上,目前有很多关于 REE 在 10.9 中支持的问题正在进行中(例如)。或者等待一周,让 RVM 团队解决问题,更新 RVM 并再次尝试。 - RyanWilcox
1
@Beaon,因为我是个好人,我已经更新了我的回答,希望你会认为这是一个真正的回答。 - RyanWilcox
显示剩余3条评论

10

当你看到这个错误信息时:

configure: error: C compiler cannot create executables

首先,请确保您已经升级了您的命令行工具:

$ xcode-select --install

现在,苹果希望你在使用这些工具之前同意他们的许可协议:

现在,苹果要求您在使用这些工具之前同意其许可证:

$ gcc
Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo.

$ sudo gcc
You have not agreed to the Xcode license agreements. You must agree to both license agreements below in order to use Xcode.
[...]

在您接受后,命令行工具将按预期工作。


我遇到了错误:“无法安装软件,因为它目前不可从软件更新服务器获取。” - nnyby
是的,我有Xcode 5.0.2。我通过从苹果开发者中心下载工具来解决这个问题。 - nnyby

8

如果您已经在OS X Mavericks上安装了开发人员工具,则Ruby 1.8已经与2.0一起安装。

所以您需要做的就是将“Current”符号链接切换到指向1.8目录。

#Install Xcode Developer tools
xcode-select --install

#Delete Current symbolic link to Ruby 2.0
sudo rm /System/Library/Frameworks/Ruby.framework/Versions/Current

#Create new Current symbolic link to Ruby 1.8
sudo ln -s /System/Library/Frameworks/Ruby.framework/Versions/1.8 /System/Library/Frameworks/Ruby.framework/Versions/Current

#Check Ruby version is 1.8.7
ruby -v

这个对我有效,尝试了两天的所有方法后。谢谢! - ssantos
顺便提一下,如果您需要回到2.0版本,只需删除符号链接,然后创建一个新的Current符号链接,将/1.8部分替换为/2.0。 - David Douglas
如果您进行了免费的操作系统升级,并安装了两个操作系统,则此方法特别有效,它可以立即解决您在ruby1.8上运行时遇到的任何问题。 - simbo1905

3

请尝试以下操作(确保开发工具链是可访问的):

$ sudo xcode-select -s /Applications/Xcode5-DP.app/Contents/Developer

然后重试。

0
尝试切换编译器。
rvm install 1.8.7 --with-gcc=clang

2
这是在寻找问题,ruby-1.8.7clang完全不兼容,最初尝试使其工作的版本是ruby-1.9.3,但只有ruby-1.9.3-p194能正常工作(最小问题),而ruby-2.0.0是第一个更适用于clang而不是gcc-4.2(GNU GCC)的版本。 - mpapis

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接