Rails OS X 10.7.3 Xcode 4.3.1 再次安装 rails 出错,求助

Standme · 2012年03月18日 · 最后由 richarddong 回复于 2012年04月27日 · 4950 次阅读

昨天下午无聊把我的 MBA 重装了系统(花了 3 个小时),全新的 OS X 10.7.3,然后是安装了 Xcode 4.3.1,在 app store 下的,4.3.1 下载之后不需要 install 就可以用了,然后下载安装了 Command Line Tools,详细的环境如下:

系统版本:Mac OS X 10.7.3 (11D50) 内核版本:Darwin 11.3.0 64 位内核和功能扩展:是 Developer Information: Version: No version information available Location: /Applications/Xcode.app Applications: Xcode: 4.3.1 (1176) Instruments: 4.3 (4321)

安装 rails 是按照网站 wiki 的介绍安装的,一步一步的来的,这次很老实,一路上也没有用 sudo,RVM 的安装没有任何问题:

rvm -v

rvm 1.10.3 by Wayne E. Seguin <[email protected]>, Michal Papis <[email protected]> [https://rvm.beginrescueend.com/]

$ rvm pkg install readline 也没问题,看到安装了 readline-5.2 和 readline-6.2,安装过程没有任何报错,然后到下一步安装 ruby1.9.3 的时候出错,出现如下错误:

ruby-1.9.3-p125 - #fetching 
ruby-1.9.3-p125 - #extracting ruby-1.9.3-p125 to /Users/standme/.rvm/src/ruby-1.9.3-p125
ruby-1.9.3-p125 - #extracted to /Users/standme/.rvm/src/ruby-1.9.3-p125
Applying patch 'xcode-debugopt-fix-r34840' (located at /Users/standme/.rvm/patches/ruby/1.9.3/p125/xcode-debugopt-fix-r34840.diff)
ruby-1.9.3-p125 - #autoreconf
Error running 'autoreconf', please read /Users/standme/.rvm/log/ruby-1.9.3-p125/autoreconf.log
ruby-1.9.3-p125 - #configuring 
Error running ' ./configure --prefix=/Users/standme/.rvm/rubies/ruby-1.9.3-p125 --enable-shared --disable-install-doc --with-readline --with-opt-dir=/Users/standme/.rvm/usr --with-libyaml --with-gcc=clang ', please read /Users/standme/.rvm/log/ruby-1.9.3-p125/configure.log
There has been an error while running configure. Halting the installation.

奇怪的是,我自行编译 autoconf 然后重新尝试安装仍然出现这个错误,用 homebrew 安装 autoconf 然后重新尝试安装还是出现这个错误,不知道为何。

查看了/Users/standme/.rvm/log/ruby-1.9.3-p125/configure.log 这个 LOG 文件,发现主要的错误信息如下:首先是这里报错:

./configure --prefix=/Users/standme/.rvm/rubies/ruby-1.9.3-p125 --enable-shared --disable-install-doc --with-readline --with-opt-dir=/Users/standme/.rvm/usr --with-libyaml --with-gcc=clang 
configure: WARNING: unrecognized options: --with-readline, --with-libyaml

最后的错误归结到这里:

.ext/include/x86_64-darwin11.3.0/ruby/config.h updated
ruby library version = 1.9.1
configure: creating ./config.status
config.status: creating Makefile
configure: WARNING: unrecognized options: --with-readline, --with-libyaml
configure: WARNING: unrecognized options: --with-readline, --with-libyaml
config.status: creating ruby-1.9.pc
./config.status: line 1113: s_fn_exit: command not found

这些代码上面都是 checking 奇怪了,最近怎么老是出现这些很纠结的错误啊

这是因为 xcode 4.3.1 默认没有安装 gcc。 别折腾了,卸载掉 xcode,直接安装 gcc。 https://github.com/kennethreitz/osx-gcc-installer

那为什么之前不少同学给我说他们也是 10.7.3,xcode4.3.1 直接安装没问题呢,莫非是之前他们安装过 gcc,xcode 和 gcc 不能共存吗

还要在 xcode 里面安装那个 command line tools

#2 楼 @Standme 在 XCode 4.3.1 下安装 Ruby 的方法是这个:

rvm install 1.9.3 --with-gcc=clang

#2 楼 @Standme clang/LLVM是mac自家的编译器,gcc是公家的,mac总是喜欢自搞一套,但目前clang还无法和gcc做到百分百兼容。 ruby 从 1.9.3-p125 开始支持 clang/LLVM: http://www.ruby-lang.org/en/news/2012/02/16/ruby-1-9-3-p125-is-released/ 你试下rvm install 1.9.3-head,还有就是参照@lgn21st 的方法指定使用 clang 编译。 但这样安装 1.8.7 的话肯定悲惨,因为 ruby 旧版本是只支持 gcc 编译的。

可以用 jruby :)

找到原因,基本搞定,不管是 autoconf 的错误还是 ruby 的错误,都是因为 mac 没有安装 gcc 编译环境所致,所以安装过 gcc 之后,一切问题将不复存在。

安装 xcode 的 command line tools 然后 xcode-select

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