Rails返回:分段错误

如果我运行rails s ,我得到:

 /Users/adam/.rvm/gems/ruby-1.9.3-p327/gems/pg-0.13.2/lib/pg_ext.bundle: [BUG] Segmentation fault ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0] Abort trap: 6 

版本:

 rails -v Rails 3.2.1 ruby -v ruby 1.9.3p327 (2012-11-10 revision 37606) [x86_64-darwin12.2.0] 

如果我使用1.9.3,为什么在错误消息中提到了ruby版本1.8.7

最初安装它时,看起来你的pg gem是针对Ruby 1.8.7编译的。 只需运行gem uninstall pg; gem install pg gem uninstall pg; gem install pg应该针对Ruby 1.9.3重新编译它。

如果你还没有,我建议使用RVM来避免这种问题。

我有一个类似的问题,运行任何bundle exec给出了分段错误:

 ~/mayapp >bundle exec rake -T /Users/rogermarlow/.rvm/gems/ruby-1.9.3-p327/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundle: [BUG] Segmentation fault ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin11.0] Abort trap: 6 

我有两个问题(1)使用1.9.3p327而不是1.9.3p125和(2)GEM_HOME环境变量指向一个现在不存在的目录。 所以我的修复是:

 ~/myapp >rvm list rvm rubies =* ruby-1.9.3-p327 [ x86_64 ] # => - current # =* - current && default # * - default ~/myapp >rvm install 1.9.3-p125 **snip** ~/myapp >rvm use 1.9.3-p125 Using /Users/rogermarlow/.rvm/gems/ruby-1.9.3-p125 Running /Users/rogermarlow/.rvm/hooks/after_use_maglev ~/myapp >echo $GEM_HOME /Users/rogermarlow/.rvm/gems/ruby-1.9.3-p125 ~/myapp ># you should check that the directory in $GEM_HOME exists, I had ...-p125@global which had been removed at some point ~/myapp >bundle install **snip** 

现在尝试bundle exec ,这是分段错误…

 ~/myapp >bundle exec rake -T rake about # List versions of all Rails frameworks and the environment rake assets:clean # Remove compiled assets rake assets:precompile # Compile all the assets named in config.assets.precompile **snip** 

我不知道你的情况如何,我之前安装了ruby 1.8.7来测试一个较旧的项目,然后我切换到我当前的rails项目文件夹,在那里我有一个.rvmrc文件,我的gemset设置为1.9.3@blabla 。 我的ruby和rails版本是正确的(1.9.3,3.2.12),但显然Postgres仍然试图使用1.8.7。 并且你提到了同样的错误。

我的解决方案

 1/ cd out of the current folder project with the .rvmrc file 2/ rvm use 1.9.3 --default 

然后我回到我目前的rails项目运行捆绑更新pg,以防万一,我不知道是否真的有任何影响, 瞧,一切正常!