Ruby on Rails - 尝试启动Rails服务器时出现Postgres错误

时间:2016-06-05 13:55:01

标签: ruby-on-rails ruby postgresql ruby-on-rails-4

我正在使用:

  • ruby​​ 2.2.1
  • rails 4.6.2
  • postgres安装自制软件
  • rbenv
  • osx el capitan 10.11.5

以下是运行时收到的错误: rails s

/usr/local/lib/ruby/gems/2.2.0/gems/pg-0.18.4/lib/pg.rb:4:in `require': dlopen(/usr/local/lib/ruby/gems/2.2.0/gems/pg-0.18.4/lib/pg_ext.bundle, 9): Library not loaded: /usr/local/lib/libruby.2.2.0.dylib (LoadError)
  Referenced from: /usr/local/lib/ruby/gems/2.2.0/gems/pg-0.18.4/lib/pg_ext.bundle
  Reason: image not found - /usr/local/lib/ruby/gems/2.2.0/gems/pg-0.18.4/lib/pg_ext.bundle
    from /usr/local/lib/ruby/gems/2.2.0/gems/pg-0.18.4/lib/pg.rb:4:in `<top (required)>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:86:in `require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:86:in `block (2 levels) in require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:81:in `each'
    from /usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:81:in `block in require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in `each'
    from /usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.12.5/lib/bundler/runtime.rb:70:in `require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/bundler-1.12.5/lib/bundler.rb:102:in `require'
    from /Users/jeffr/Dropbox/DevelopmentPC/rails4/myapp/config/application.rb:7:in `<top (required)>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:78:in `require'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:78:in `block in server'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `tap'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:75:in `server'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
    from /usr/local/lib/ruby/gems/2.2.0/gems/railties-4.2.6/lib/rails/commands.rb:17:in `<top (required)>'
    from /Users/jeffr/Dropbox/DevelopmentPC/rails4/myapp/bin/rails:9:in `require'
    from /Users/jeffr/Dropbox/DevelopmentPC/rails4/myapp/bin/rails:9:in `<top (required)>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `load'
    from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/client/rails.rb:28:in `call'
    from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/client/command.rb:7:in `call'
    from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/client.rb:30:in `run'
    from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.7.1/bin/spring:49:in `<top (required)>'
    from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `load'
    from /usr/local/lib/ruby/gems/2.2.0/gems/spring-1.7.1/lib/spring/binstub.rb:11:in `<top (required)>'
    from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /Users/jeffr/Dropbox/DevelopmentPC/rails4/myapp/bin/spring:13:in `<top (required)>'
    from bin/rails:3:in `load'
    from bin/rails:3:in `<main>'

1 个答案:

答案 0 :(得分:0)

我最终开始使用整个rbenv,ruby和rails安装。

brew update

brew uninstall --force ruby

brew uninstall --force openssl

brew install openssl

brew link openssl --force

brew uninstall --force ruby-build

然后我按照本指南进行操作: https://gorails.com/setup/osx/10.11-el-capitan

安装rails时出现libxml2错误:

libxml2 is missing.  Please locate mkmf.log to investigate how it is failing.

我通过运行

修复了这个问题
$  gem install nokogiri -- --use-system-libraries  [--with-xml2-config=/path/to/xml2-config]  [--with-xslt-config=/path/to/xslt-config]