RVM/rbenv Mac OS 10.7.5 用 RVM 安装 ruby 失败?是 gcc 的问题吗?

evil850209 · 2012年12月16日 · 最后由 evil850209 回复于 2013年06月11日 · 6406 次阅读

RVM 版本 rvm 1.17.3 Mac OS 版本 10.7.5 Xcode 版本 4.5

运行 rvm install ruby 时,出现如下错误:

bogon:~ chris$ rvm install ruby
No binary rubies available for: downloads/ruby-1.9.3-p327.
Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies.
Fetching yaml-0.1.4.tar.gz to /Users/chris/.rvm/archives
Extracting yaml to /Users/chris/.rvm/src/yaml-0.1.4
Configuring yaml in /Users/chris/.rvm/src/yaml-0.1.4.
Error running 'env LDFLAGS=-L/opt/sm/pkg/active/lib CFLAGS=-I/opt/sm/pkg/active/include CPATH=/opt/sm/pkg/active/include ./configure --prefix=/Users/chris/.rvm/usr', please read /Users/chris/.rvm/log/ruby-1.9.3-p327/yaml/configure.log
Compiling yaml in /Users/chris/.rvm/src/yaml-0.1.4.
Installing yaml to /Users/chris/.rvm/usr
Installing Ruby from source to: /Users/chris/.rvm/rubies/ruby-1.9.3-p327, this may take a while depending on your cpu(s)...
ruby-1.9.3-p327 - #downloading ruby-1.9.3-p327, this may take a while depending on your connection...
ruby-1.9.3-p327 - #extracted to /Users/chris/.rvm/src/ruby-1.9.3-p327 (already extracted)
ruby-1.9.3-p327 - #configuring
Error running 'env LDFLAGS=-L/opt/sm/pkg/active/lib CFLAGS=-I/opt/sm/pkg/active/include CPATH=/opt/sm/pkg/active/include ./configure --enable-shared --disable-install-doc --prefix=/Users/chris/.rvm/rubies/ruby-1.9.3-p327 --with-opt-dir=/Users/chris/.rvm/usr', please read /Users/chris/.rvm/log/ruby-1.9.3-p327/configure.log
There has been an error while running configure. Halting the installation.

请问各位是否有同样问题?

贴一下 log: /Users/chris/.rvm/log/ruby-1.9.3-p327/configure.log

@lyfi2003

[2012-12-16 20:45:44] env LDFLAGS=-L/opt/sm/pkg/active/lib CFLAGS=-I/opt/sm/pkg/active/include CPATH=/opt/sm/pkg/active/include ./configure --enable-shared --disable-install-doc --prefix=/Users/chris/.rvm/rubies/ruby-1.9.3-p327 --enable-shared --with-opt-dir=/Users/chris/.rvm/usr checking build system type... x86_64-apple-darwin11.4.2 checking host system type... x86_64-apple-darwin11.4.2 checking target system type... x86_64-apple-darwin11.4.2 checking whether the C compiler works... no configure: error: in /Users/chris/.rvm/src/ruby-1.9.3-p327': configure: error: C compiler cannot create executables Seeconfig.log' for more details

#2 楼 @evil850209 checking whether the C compiler works... no 请安装 xcode , 并安装 command tool 后再安装。

xcode 已经安装,command tool 也安装了,并且重启电脑。问题依旧。 好像是我的 xcode 版本问题,没有 ruby 需要的 gcc

#4 楼 @evil850209 这是我的情况:

gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

rvm 1.13.1 () by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/] 我的 MacOSX 版本为: 10.8.2

你可以试着更新下 rvm, 另外, xcode 的某些版本 gcc 有些问题,详细你可以试着 google 下。

rvm 已经更新了,版本号和 xcode 的版本我已经列出

gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00) rvm 1.17.3 (latest) by Wayne E. Seguin wayneeseguin@gmail.com, Michal Papis mpapis@gmail.com [https://rvm.io/]

已经安装了 GCC-10.7-v2,并重启电脑,问题依然存在,请问谁能正常再 10.7 OS 安装 ruby 呢?

#7 楼 @evil850209 肯定是能装的呀

你确定你每次出错的提示都是相同的?

@huacnlee 终端中的错误信息一样,具体 log 还没仔细看。但都是 configure: error: C compiler cannot create executables

有没有具体步骤,我重头来一遍? PS:按照 wiki 上的做了,同样的错误。

#9 楼 @evil850209 mac 下,可以参考 xdite 的《Rails on Mac 安裝最佳實務》

http://blog.xdite.net/mac-lion-xcode-ruby-rails-192/

@xiaogui 链接打不开呢?需要翻墙吗?

#11 楼 @evil850209 不用的吧,我打开也不太顺流。

@xiaogui 现在运行 ruby -v 出现

bogon:~ chris$ ruby -v /Users/chris/.rvm/bin/ruby: line 6: /Users/chris/.rvm/bin/ruby: Argument list too long /Users/chris/.rvm/bin/ruby: line 6: /Users/chris/.rvm/bin/ruby: Undefined error: 0

所以 homebrew 都装不了,貌似 rvm 把我系统自带的 ruby 都给卸载了。自带的 ruby 在哪个路径下呢?

#14 楼 @evil850209 说明 ruby 没安装成功 你是用 rvm install 1.9.3 --with-gcc=clang 安装的吗?

@xiaogui 对,带不带 gcc 参数都用了

是不是 gcc 的版本问题? 大家帮我看看我的 gcc 是否不对

bogon:~ chris$ gcc -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2336.11~67/src/configure --disable-checking --enable-werror --prefix=/Applications/Xcode.app/Contents/Developer/usr/llvm-gcc-4.2 --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-prefix=llvm- --program-transform-name=/^[cg][^.-]*$/s/$/-4.2/ --with-slibdir=/usr/lib --build=i686-apple-darwin11 --enable-llvm=/private/var/tmp/llvmgcc42/llvmgcc42-2336.11~67/dst-llvmCore/Developer/usr/local --program-prefix=i686-apple-darwin11- --host=x86_64-apple-darwin11 --target=i686-apple-darwin11 --with-gxx-include-dir=/usr/include/c++/4.2.1
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

这是 log 文件中的日志:

[2012-12-18 21:08:46] env LDFLAGS=-L/opt/sm/pkg/active/lib CFLAGS=-I/opt/sm/pkg/active/include CPATH=/opt/sm/pkg/active/include ./configure --enable-shared --disable-install-doc --prefix=/Users/chris/.rvm/rubies/ruby-1.9.3-p327 --with-readline --with-opt-dir=/usr/local/Cellar/readline/6.2.4 --with-opt-dir=/Users/chris/.rvm/usr
configure: WARNING: unrecognized options: --with-readline
checking build system type... x86_64-apple-darwin11.4.2
checking host system type... x86_64-apple-darwin11.4.2
checking target system type... x86_64-apple-darwin11.4.2
checking whether the C compiler works... no
configure: error: in `/Users/chris/.rvm/src/ruby-1.9.3-p327':
configure: error: C compiler cannot create executables
See `config.log' for more details

今天回来首先安装了 xcode4.2,然后安装了 command line tools. 接着按照这个 http://blog.xdite.net/mac-lion-xcode-ruby-rails-192/ 安装了 homebrew,然后安装 brew install apple-gcc42 还是报错,configure: error: C compiler cannot create executables

我记得 xcode 4.2 没有 clang 吧? which clang 看看, 我猜因为没有 clang 所以用 --with-gcc=clang 才会报 "C compiler cannot create executables".

xcode 4.5 有 clang, 没有 clang 的机器才用 apple-gcc42, 用 gcc42 的话

export CC=`which gcc-4.2`

然后删掉源代码目录 (~/.rvm/src/...), 然后再 rvm install

这两个都可以:

$ clang -v
Apple clang version 4.1 (tags/Apple/clang-421.11.65) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.2.1
Thread model: posix

$ gcc-4.2 -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: ...
Thread model: posix
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)

这个就不能行:

$ gcc -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: ...
Thread model: posix
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)

已经安装了一个 RAILSINSTALLER,现在卸载了,然后按照这个做: http://lixiaolai.com/alpha/notes/HomeBrew.html

目前编译中,应该找到 c 编译器了。

终于安装好了,最后卸载 RAILSINSTALLER,就可以了,可能是系统选择 GCC 时选择那个不想用的原因。希望有那位高手给解释一下。

但现在有了新的问题, 1 每次 shell 启动的时候都有这么两句:

-bash: /etc/profile.d/sm.sh: No such file or directory
-bash: /etc/profile.d/rvm.sh: No such file or directory

2 当我想用 taobao 源替换 rvm 默认的时候,出现这个问题:

sed -i 's/ftp\.ruby-lang\.org\/pub\/ruby/ruby\.taobao\.org\/mirrors\/ruby/g' ~/.rvm/config/db
sed: 1: "/Users/chris/.rvm/confi ...": command c expects \ followed by text

继续研究中,哎,学习 ruby 最大的障碍难道是不同系统和版本的安装?

#23 楼 @evil850209

可能你没有 C 有关基础, Ruby(MRI) 是用 C 实现的, 能用的编译器如我上面说的有 gcc 和 clang, 而 llvm-gcc 不行. 编译第一步是 ./configure, 检测环境并产生 makefile, 这时就决定好了用哪个编译器, 如果你一开始编译出错了, 然后换了编译器, 应该把源代码目录删掉再继续.

选择 GCC 最简单的方式就是 configure 之前

export CC=`your path to gcc`

替换源直接打开文件编辑 ~/.rvm/config/db 替换 ftp.ruby-lang.org/pub/ruby.taobao.org/mirrors/ 就好了嘛...

最大的障碍是 Mac 更新很快很频繁, ruby 相关的开发也很活跃, 所以大部分教程都会很快过时, 然后无头苍蝇般每个都弄一遍结果就是像你这样产生奇怪的问题, 按照 rvm requirements 去做是不会出问题的...

@luikore 谢谢, 受益匪浅

#25 楼 @evil850209 你日志里面已经说了

checking whether the C compiler works... no
configure: error: in /Users/chris/.rvm/src/ruby-1.9.3-p327':
configure: error: C compiler cannot create executables
Seeconfig.log' for more details

@xiaogui 最后解决了,@luikore 的方法奏效。

#24 楼 @luikore 授人于渔,thx

想问下楼主,像我下面出现的问题,有点似你贴里提的,有没有什么见解分享下呢。

$rvm install 1.9.3

Searching for binary rubies, this might take some time. No binary rubies available for: osx/10.7/x86_64/ruby-1.9.3-p392. Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies. Installing requirements for osx, might require sudo password. Skipping brew update make sure your formulas are up to date. Cowardly refusing to continue, please read 'rvm autolibs'.

@Jijin 你可以参见 24 楼 luikore 的回复,已经说的非常清楚了。按照他的做法,应该就没有问题。

#31 楼 @evil850209 您好!我在安装 Rails 的时候遇到下面的问题,感觉跟你的也有相似之处,你能不能帮我看一下该如何解决呢? 问题总结如下:

  1. rvm install 1.9.2-p320 之后存在下述问题: [user@cloud-privacy 下载]$ rvm install ruby-1.9.2-p320 Searching for binary rubies, this might take some time. No binary rubies available for: fedora/14/i386/ruby-1.9.2-p320. Continuing with compilation. Please read 'rvm mount' to get more information on binary rubies. Installing requirements for fedora, might require sudo password. ccache: failed to create /var/cache/ccache/tmp (Permission denied) Installing Ruby from source to: /home/user/.rvm/rubies/ruby-1.9.2-p320, this may take a while depending on your cpu(s)... ruby-1.9.2-p320 - #downloading ruby-1.9.2-p320, this may take a while depending on your connection... ruby-1.9.2-p320 - #extracted to /home/user/.rvm/src/ruby-1.9.2-p320 (already extracted) ruby-1.9.2-p320 - #configuring........ Error running 'env LDFLAGS=-L/opt/sm/pkg/active/lib CFLAGS=-O3 -I/opt/sm/pkg/active/include CPATH=/opt/sm/pkg/active/include ./configure --prefix=/home/user/.rvm/rubies/ruby-1.9.2-p320 --disable-install-doc --enable-shared', please read /home/user/.rvm/log/ruby-1.9.2-p320/1370654543_configure.log There has been an error while running configure. Halting the installation.

  2. /home/user/.rvm/log/ruby-1.9.2-p320/1370654543_configure.log 的内容如下: 1 hecking build system type... i686-pc-linux-gnu 2 checking host system type... i686-pc-linux-gnu 3 checking target system type... i686-pc-linux-gnu 4 checking for gcc... gcc 5 checking whether the C compiler works... no 6 configure: error: in /home/user/.rvm/src/ruby-1.9.2-p320': 7 configure: error: C compiler cannot create executables 8 Seeconfig.log' for more details

期待您的回复!

@zhangyuxiu 先按照 luikore 21 楼说的查看一下,然后按照 24 楼说的做。估计还是编译器的问题。

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册