Mac OS X 10.10,安装有Xcode5 和 Xcode 6 beta,command line tools选的是Xcode 5的,我是Ruby初学者
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/2.0/usr/bin/ruby extconf.rb
creating Makefile
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
In file included from ./../fbuffer/fbuffer.h:5:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
^
1 error generated.
make: *** [generator.o] Error 1
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/json-1.8.1 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
使用RVM安装发现了新的问题
Error running 'requirements_osx_brew_update_system ruby-2.1.2',
showing last 15 lines of /Users/tinyfool/.rvm/log/1402459044_ruby-2.1.2/update_system.log
https://github.com/Homebrew/homebrew/wiki/Common-Issues
and make sure `brew update` works before continuing.'
++ rvm_pretty_print stderr
++ case "${rvm_pretty_print_flag:=auto}" in
++ case "${TERM:-dumb}" in
++ case "$1" in
++ [[ -t 2 ]]
++ return 1
++ printf %b 'Failed to update Homebrew, follow instructions here:
https://github.com/Homebrew/homebrew/wiki/Common-Issues
and make sure `brew update` works before continuing.n'
Failed to update Homebrew, follow instructions here:
https://github.com/Homebrew/homebrew/wiki/Common-Issues
and make sure `brew update` works before continuing.
++ return 1
Requirements installation failed with status: 1.
但是brew update也报错,唉,简直就是俄罗斯套娃错误啊
brew update
/usr/local/bin/brew: /usr/local/Library/brew.rb: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby: bad interpreter: No such file or directory
/usr/local/bin/brew: line 21: /usr/local/Library/brew.rb: Undefined error: 0
搜到了这个 https://gist.github.com/chrisb/4d6a09c6cc1ca2e1b14e 目测是因为homebrew 还在用ruby 1.8而10.10上没有1.8导致的问题...总之还是要装xcode 6 command line tools
14楼 @jiangzhoubai https://gist.github.com/chrisb/4d6a09c6cc1ca2e1b14e 这里面有个链接试试?
8楼 @tinyfool 因为 Yosemite 刚刚出来,配套的包管理工具如 brew 或者 gem 都兼容问题,不过这些问题在近几天都会陆续解决。
我还未升级到 Yosemite,这里有个方案,仅供参考 https://gist.github.com/chrisb/4d6a09c6cc1ca2e1b14e
sudo gem install rails
然后
rails new democodes
没出现问题
然后
cd democodes
rails server
然后报错
Warning: You're using Rubygems 2.0.14 with Spring. Upgrade to at least Rubygems 2.1.0 and run `gem pristine --all` for better startup performance.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/yaml.rb:4:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/yaml.rb:4:in `<top (required)>':
It seems your ruby installation is missing psych (for YAML output).
To eliminate this warning, please install libyaml and reinstall your ruby.
bin/rails:6: warning: already initialized constant APP_PATH
/Users/tinyfool/work/democodes/bin/rails:6: warning: previous definition of APP_PATH was here
这是说Xcode 6的Ruby也不行么?
OSX Builtin 各种脚本语言环境,包括 Ruby,Python,PHP,还有 JavaScript,但是这些自带的脚本有两个问题:
那么谁会使用系统自带的 Ruby 呢?
为了解决开发的问题,通常最佳实践是不使用系统默认的ruby,而是用普通用户自己在本地编译一套,为了本地编译ruby,ruby社区专门为各个平台制作了一些ruby版本管理套件,比较流行的是 rvm 或者 rbenv,rvm 和 rbenv 各有优劣,就像 vim 和 emacs 一样,选择那种,看你个人的偏好以及习惯。
ruby版本管理器的做法通常是在本地 ~/.rvm 或者 ~/.rbenv 里面编译一套ruby,并且修改系统 env,把自己的搜索路径添加到 PATH 环境变量的前面,并通过一些 shell 的技术可以让你拥有多个版本的 ruby 且灵活切换,总的来说,推荐通过 rvm 或者 rbenv 在用户本地安装一套 ruby,然后就跟 sudo 彻底说再见了。
我刚刚查看了一下,OSX 10.10 的安装教程已经很容易找到了,比较推荐 goRails 的这篇,比较权威,且更新比较及时。
Yosemite 自带的 ruby 是 2.0 的, homebrew 基于1.8,目前的解决方案是 ln 一个 2.0 到 1.8 的路径,不保证完全能用。
刚发现homebrew在6.3已经更新到使用Current的Ruby了,只是brew update没法用,于是git pull之后git reset --hard origin/master就好了..