【问题标题】:Ruby on Rails - Postgres error when trying to start Rails ServerRuby on Rails - 尝试启动 Rails 服务器时出现 Postgres 错误
【发布时间】:2016-06-05 13:55:01
【问题描述】:

我正在使用:

  • 红宝石 2.2.1
  • 导轨 4.6.2
  • 用于安装 postgres 的自制软件
  • rbenv
  • osx el capitan 10.11.5

这是我在运行时收到的错误: 轨道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>'

【问题讨论】:

  • 我们能看到Gemfileconfig/database.yml吗?
  • 似乎二进制扩展被破坏了...尝试删除gem缓存和重新捆绑环境,认为您可以从缓存中删除pg gem并重新捆绑它
  • 感谢您清理错误信息 CupanwTae

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


【解决方案1】:

我最终重新开始安装整个 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]

【讨论】:

    最近更新 更多