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

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

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.

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

共收到 33 条回复
121

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

3969

@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

121

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

3969

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

121

#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 下。

3969

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/]

3969

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

De6df3

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

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

3969

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

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

667

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

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

3969

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

667

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

3969

@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在哪个路径下呢?

667

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

3969

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

3969

是不是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)
3969

这是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
3969

今天回来首先安装了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

2880

我记得 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

2880

这两个都可以:

$ 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)
3969

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

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

3969

终于安装好了,最后卸载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最大的障碍难道是不同系统和版本的安装?

2880

#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 去做是不会出问题的...

3969

@luikore 谢谢, 受益匪浅

667

#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
3969

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

667

#27楼 @evil850209 那就好 呵呵

4113

#24楼 @luikore 授人于渔,thx

54c6da

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

$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'.

3969

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

5191

#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

期待您的回复!

3969

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

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