在Mountain Lion上安装Ruby时出现问题 - Ruby 1.9.3编译失败。

11

我以前看过很多关于这个问题的帖子,并遵循了它们的指示,但没有任何作用。我将在下面概述我所做的事情以及我所遵循的说明 - 如果有任何建议,我将不胜感激!

我按照以下安装说明进行操作: http://pragmaticstudio.com/blog/2010/9/23/install-rails-ruby-mac

我已经为OSX Mountain Lion下载了X-code并安装了gcc编译器:

$ gcc --version
i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

我按照指示安装了最新版本的git。

$ git --version
git version 1.7.10.2 (Apple Git-33)

同样,也可以通过命令行使用 rvm 进行相似的操作:

$ rvm --version
rvm 1.16.13 (stable) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

当我试图使用RVM安装Ruby时,我会得到以下错误信息:

$ rvm install 1.9.3
No binary rubies available for: osx/10.8/x86_64/ruby-1.9.3-p286.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Installing Ruby from source to: /Users/mondemoo/.rvm/rubies/ruby-1.9.3-p286, this may take a while depending on your cpu(s)...
ruby-1.9.3-p286 - #downloading ruby-1.9.3-p286, this may take a while depending on your connection...
ruby-1.9.3-p286 - #extracted to /Users/mondemoo/.rvm/src/ruby-1.9.3-p286 (already extracted)
ruby-1.9.3-p286 - #configuring
Error running 'env LDFLAGS=-L/opt/sm/pkg/active/lib CFLAGS=-I/opt/sm/pkg/active/include CPATH=/opt/sm/pkg/active/include -L/Users/mondemoo/.rvm/usr/lib ./configure --enable-shared --disable-install-doc --prefix=/Users/mondemoo/.rvm/rubies/ruby-1.9.3-p286', please read /Users/mondemoo/.rvm/log/ruby-1.9.3-p286/configure.log
There has been an error while running configure. Halting the installation.

使用替代命令行时,我得到了类似的输出,但是有一些额外的部分:

$ rvm install 1.9.3 --with-gcc=clang
-bash: -dumpversion: command not found
-bash: --version: command not found
-bash: --version: command not found
Installing Ruby from source to: /Users/mondemoo/.rvm/rubies/ruby-1.9.3-p286, this may take a while depending on your cpu(s)...
ruby-1.9.3-p286 - #downloading ruby-1.9.3-p286, this may take a while depending on your connection...
ruby-1.9.3-p286 - #extracted to /Users/mondemoo/.rvm/src/ruby-1.9.3-p286 (already extracted)
ruby-1.9.3-p286 - #configuring
Error running 'env LDFLAGS=-L/opt/sm/pkg/active/lib CFLAGS=-I/opt/sm/pkg/active/include CPATH=/opt/sm/pkg/active/include -L/Users/mondemoo/.rvm/usr/lib ./configure --enable-shared --disable-install-doc --prefix=/Users/mondemoo/.rvm/rubies/ruby-1.9.3-p286 --with-gcc=clang', please read /Users/mondemoo/.rvm/log/ruby-1.9.3-p286/configure.log
There has been an error while running configure. Halting the installation.
-bash: --version: command not found

查看configure.logs,我得到以下内容:

$ less /Users/mondemoo/.rvm/log/ruby-1.9.3-p286/configure.log
[2012-10-17 07:39:15] env LDFLAGS=-L/opt/sm/pkg/active/lib CFLAGS=-I/opt/sm/pkg/active/include CPATH=/opt/sm/pkg/active/include -L/Users/mondemoo/.rvm/usr/lib ./configure --enable-shared --disable-install-doc --prefix=/Users/mondemoo/.rvm/rubies/ruby-1.9.3-p286 --with-gcc=clang
checking build system type... x86_64-apple-darwin12.2.0
checking host system type... x86_64-apple-darwin12.2.0
checking target system type... x86_64-apple-darwin12.2.0
checking whether the C compiler works... no
configure: error: in `/Users/mondemoo/.rvm/src/ruby-1.9.3-p286':
configure: error: C compiler cannot create executables
See `config.log' for more details

我现在非常困惑,不知道我做错了什么 - 有人能帮助吗??看起来出现了一个与C编译器(gcc?)有关的问题,我是否理解正确?如果是这样,我该如何修复它?还有,如何进入上面提到的“config.log”文件?

谢谢!


请使用四个空格缩进格式化您的帖子来输出终端内容。 - Ryan Bigg
1
那么配置日志显示了什么? - halfelf
请阅读 /Users/mondemoo/.rvm/log/ruby-1.9.3-p286/configure.log,它会有礼貌地告诉你相关信息。 - Warren Burton
谢谢Ryan,我刚刚发现了如何缩进 :-) Half-elf& Warren,我刚刚添加了configure.log文件的内容。 - MrBernz
2个回答

22
这是RailsInstaller OSX 1.0.3中的一个错误-https://github.com/railsinstaller/railsinstaller-nix/issues/10 你需要更改/etc/rvmrc,使其包含以下内容:
umask g+w
export -a rvm_configure_env
rvm_configure_env=('LDFLAGS=-L/opt/sm/pkg/active/lib' 'CFLAGS=-I/opt/sm/pkg/active/include' 'CPATH=/opt/sm/pkg/active/include')

当二进制Ruby可用于2.0.0时,我将准备新版本的安装程序。

更新:对于RVM的新版本1.19+/etc/rvmrc应更改为:

umask g+w
export rvm_autolibs_flag=smf

运行 rvm get stable #或者:head


忽略我之前的帖子,刚看到这一行还在继续 - 我现在会尝试它。 - MrBernz
非常感谢!这对我有用……还有安装 Ruby 2.0.0。 - markstewie
所以现在是2013年4月11日,这个问题仍然没有解决。为什么Rails总是有问题,我一生中最常谷歌的就是Rails安装或设置问题的错误信息。 - nonopolarity
我执行了 more /etc/rvmrc 命令,但是没有这个文件。太好了。 - nonopolarity
更新rvm应该可以修复它或者向你展示如何修复它,这个问题发生在你的系统上,无法通过远程自动修复 - 你需要采取行动来解决它...最重要的是阅读你运行的命令的输出。 - mpapis

1

我不确定我是否以“正确”的方式完成了它,但我只是删除了RVM(rvm implode),然后重新安装它(\curl -L https://get.rvm.io | bash -s stable --ruby),它已经成功安装并运行了最新版本的ruby 1.9.3-p327。


我实际上又让它重新工作了,但是我仍然在构建其他需要本机扩展的东西时遇到其他问题。 :( - Adron

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