2012-06-12 60 views
0

我已经决定开始尝试使用Ruby来摆脱我的小Java框,并且希望从一些个人项目开始,以一些书面地址和地理编码为基础。如何在OS X 10.6.8中设置Ruby?

作为开始,我得到了Koans,并开始在命令行中使用它们,只是使用安装在OS X中的Ruby(ruby -version返回1.8.7)。到现在为止还挺好。然后我用gem install geocoder,很好地工作。但也有一些它的对象的工作,它需要JSON,所以到时gem install json ...

WARNING: Installing to ~/.gem since /Library/Ruby/Gems/1.8 and 
     /usr/bin aren't both writable. 
WARNING: You don't have /Users/sharakan/.gem/ruby/1.8/bin in your PATH, 
     gem executables will not run. 
Building native extensions. This could take a while... 
ERROR: Error installing json: 
    ERROR: Failed to build gem native extension. 

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb 
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h 


Gem files will remain installed in /Users/sharakan/.gem/ruby/1.8/gems/json-1.7.3 for inspection. 
Results logged to /Users/sharakan/.gem/ruby/1.8/gems/json-1.7.3/ext/json/ext/parser/gem_make.out 

的gem_make.out文件只是具有相同的mkmf.rb错误。

经过一番搜索之后,我发现有类似声音问题的人通过安装XCode发现了解决方案。我很久没有见过我的XCode DVD了,现在Apple提供的版本需要10.7。

我还发现一些信息,使RVM听起来像它可能会解决问题。但遗憾的是,编译问题也失败了:

[2012-06-11 20:50:00] ./configure --prefix=/Users/sharakan/.rvm/rubies/ruby-1.9.3-p194 --enable-shared --disable-install-doc --with-libyaml --with-opt-dir=/Users/sharakan/.rvm/usr 
configure: WARNING: unrecognized options: --with-libyaml 
checking build system type... i386-apple-darwin10.8.0 
checking host system type... i386-apple-darwin10.8.0 
checking target system type... i386-apple-darwin10.8.0 
checking for gcc... gcc 
checking whether the C compiler works... no 
configure: error: in `/Users/sharakan/.rvm/src/ruby-1.9.3-p194': 
configure: error: C compiler cannot create executables 
See `config.log' for more details 

那么下一步该去哪里?我真的需要购买Lion来让Ruby在我的机器上工作吗?

+0

检查自制和rbenv。我想'brew doctor'应该让你安装rbenv –

回答

1

如果您的问题没有安装xcode,您只需要安装make,gcc等。

最简单的方式做到这一点,只需使用OS X GCC Installer

安装,应该让你对你的方式。

+0

像魅力一样工作,比我在Apple's Dev网站上最终找到的XCode 3.x安装程序小得多。谢谢! – sharakan

1

您可以从Apple开发人员网站获得Snow Leopard版本的Xcode/Developer Tools。你可能也想看看Kenneth Reitz的Xcode, GCC and Homebrew:独立的GCC工具,没有Xcode。还有一个官方的苹果分支,虽然这可能只是狮子。

+0

从Apple设置的CLI工具看起来就像我想要的,但事实上它只适用于Lion,正如你怀疑的那样。 – sharakan

+0

SL有https://github.com/downloads/kennethreitz/osx-gcc-installer/GCC-10.6.pkg。 –

+0

Ruby尚未完全支持'clang' /'LLVM',这是由** Xcode 4.2 + **提供的编译器,您需要Xcode 4.1或osx-gcc-installer,它提供'gcc-4.2' a ** GNU **版本的'gcc'。 – mpapis

0

使用RVM安装ruby。我强烈建议使用RVM,特别是如果你将可能有可能使用不同版本的Ruby的多个项目(甚至是JRuby的!)

https://rvm.io/rvm/install/

+0

是的,但正如我在问题中提到的,RVM给了我其他的错误。 – sharakan