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,但是这些自带的脚本有两个问题:
- 这些语言都是默认安装到 root 用户环境的,普通用户可以直接用系统ruby执行一些管理脚本,但是如果要扩展安装第三方库或者插件,则需要 sudo 权限,这么做并不环保,也带来很安装上的问题,比如有些库或者插件需要通过 Clang 编译,编译的过程本身也需要 sudo 权限,以及编译过程需要的依赖库,也都需要通过 sudo 提前安装配置好。
- 这些默认语言的版本都比较低,而且升级不方便,自带的库只适用于运行一些服务器端管理脚本,以及一些简单的文件和进程,网络操作,对于做应用则远远不够,因为原因1的关系,不适宜扩展。
那么谁会使用系统自带的 Ruby 呢?
- 通常一些第三方的工具会用,比如 homebrew
- 系统管理员自己写的一些管理脚本可能会用到
为了解决开发的问题,通常最佳实践是不使用系统默认的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 的路径,不保证完全能用。
相关新闻
- 你真的想要一个AI小 gadgets?(注意:gadget一词可以理解为“小工具”或“小玩意”,此处根据上下文可能译为“设备”更合适。如果需要更加精准的翻译,请提供更多的上下文信息。如果没有更多信息,输出原文:Do you really want an AI gadget?) 由于要求只输出翻译结果且不添加任何注释,则直接翻译如下: 你真的想要一个AI小工具吗?
- 亿万富翁以色列·英格兰格正在出售英伟达和派拉蒙的股票,并大举买入一只历史上价格低廉、但潜在问题重重的人工智能(AI)股票 | 华尔街日报注:原文提到的Palantir应为The Motley Fool网站报道中的误植,通常提及的是另一家科技公司。鉴于此,原文可能指代有误或信息不准确,故保留英文名称Palantir以示明确。然而,根据上下文和通用理解,如果需要进一步具体化,则可能涉及其他特定的AI相关公司股票。
