见鬼了。这样执行以后出现下列错误。系统是 mac os x lion
➜ ~ gem install bundler rails
ruby(47463,0x7fff72b6d960) malloc: *** error for object 0x7fa8ab137aa0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
➜ ~ gem -v
1.8.10
➜ ~ gem list
*** LOCAL GEMS ***
➜ ~ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]
➜ ~
你倒不如完整贴出 console 里面的 log,从执行开始一直到结束。
gem install bundler rails
安装过程中会安装所有的依赖包,而有些 gem 包是带有 C 扩展的,而你遇到的可能是环境依赖问题或者是编译环境的问题,你安装的是 XCode 4.2.1 么?给出你的 gcc 版本信息
gcc -v
新版本的 XCode 4.2.1 移除了 gcc , 默认使用 llvm,这个有可能是问题的根源,为了兼容性考虑,现阶段最佳方案是安装 XCode 4.1 而不是最新版本。
➜ ~ gcc -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2335.15~25/src/configure --disable-checking --enable-werror --prefix=/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-2335.15~25/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 2335.15.00)
逼着我装 ubuntu.= =
#2 楼 @KennX 那到不必,最近我重新装过一遍 Lion,也是被这个问题折腾了好久,很可能是用 XCode 编译出来的 ruby-1.9.2-p290 的问题,目前也没有完全搞定,我已经下载好了 XCode 4.1,逼急了我就把 XCode 的版本降级回去。你可以按照这篇文章里面的方案先试试看: http://rors.org/2011/10/25/compiling-ruby-on-a-fresh-lion-install.html
我之前也有这个类似的 GCC 版本问题,不过这个有怪了,目前我这台上面 GCC 就是这个版本
➜ ~ gcc -v
Using built-in specs.
Target: i686-apple-darwin11
Configured with: /private/var/tmp/llvmgcc42/llvmgcc42-2335.15~108/src/configure --disable-checking --enable-werror --prefix=/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-2335.15~108/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 2335.15.00)
~ $ rvm requirements
Notes for Darwin ( Mac OS X )
For Snow Leopard: Xcode Version 3.2.1 (1613) or later, such as 3.2.6 or Xcode 4.1.
[ Please note that Xcode 3.x will *not* work on OS X Lion. The 'cross-over' is Xcode 4.1. ]
You should download the Xcode tools from developer.apple.com, since the Snow Leopard dvd install contained bugs.
You can find Xcode 4.1 for OS X Lion at:
https://developer.apple.com/downloads/download.action?path=Developer_Tools/xcode_4.1_for_lion/xcode_4.1_for_lion.dmg
** Lion Users: Xcode Version 4.2.x for OS X Lion works only for ruby 1.9.3-p0 (or higher).
It currently fails to build several other rubies and gems, as well as several Homebrew and
Macports packages. Xcode Version 4.1 (4B110) works.
** NOTE: Currently, Node.js is having issues building with osx-gcc-installer. This is _not_ an RVM issue. This is
because Node.js depends on the Carbon headers. ox-gcc-installer does not install these to the system.
This issue only affects users using osx-gcc-installer, and not Xcode. The only fix is to install Xcode over osx-gcc-installer.
For MacRuby: Install LLVM first.
For JRuby: Install the JDK. See http://developer.apple.com/java/download/ # Current Java version 1.6.0_26
For IronRuby: Install Mono >= 2.6
For Ruby 1.9.3: Install libksba # If using Homebrew, 'brew install libksba'
To use an RVM installed Ruby as default, instead of the system ruby:
rvm install 1.8.7 # installs patch 352: closest supported version
rvm system ; rvm gemset export system.gems ; rvm 1.8.7 ; rvm gemset import system.gems # migrate your gems
rvm --default 1.8.7
刚刚测试了一下 Lion + Xcode 4.2 安装 1.9.2-p290 跟 1.9.3-p0 的时候,只要加上--with-gcc=clang 就可以了。Clang(http://en.wikipedia.org/wiki/Clang) 就是个 LLVM 版的 GCC
#8 楼 @southwolf 的确,我目前用的 ruby 1.9.2 就是用这个方法才装上的,为此我还花了点时间研究了一些 C 编译环境,这里有一张图片,解释 GCC,LLVM 和 Clang 我认为最为清楚。
安装了 Xcode 4.2 以后 /usr/bin/gcc 其实是 llvm-gcc-4.2 的软链接,编译 Ruby 1.9 可能会有问题。
不需要降级 Xcode,rvm install 之前设置 CC 和 CXX 环境变量来指定使用 gcc 即可
export CC=/usr/bin/gcc-4.2
export CXX=/usr/bin/g++-4.2
#9 楼 @lgn21st 最新的 LLVM 3.0 放弃 llvm-gcc 了
http://llvm.org/docs/ReleaseNotes.html#whatsnew
llvm-gcc is no longer supported, and not included in the release. We recommend switching to Clang or DragonEgg.
我升级了 Xcode 也遇到这个问题 rvm install 1.9.3 --with-gcc=clang
Xcode 中编译器版本的原因 参考 http://stackoverflow.com/questions/8032824/cant-install-ruby-under-lion-with-rvm-gcc-issues
rvm install 1.9.3 --with-gcc=clang 报错 看来只能装 xcode4.1 了
[2012-05-09 10:39:08] tar xjf /Users/x/.rvm/archives/ruby-1.9.3-p194.tar.bz2 -C /Users/x/.rvm/tmp/rvm_src_2042 ruby-1.9.3-p194/template/encdb.h.tmpl: (Empty error message) tar: Error exit delayed from previous errors.