Ruby on Rails + PostgreSQL应用程序无法在AWS EC2上启动。错误是:“无法加载此类文件 - pg_ext(LoadError)”

时间:2012-09-14 21:47:49

标签: ruby-on-rails-3 postgresql rubygems amazon-web-services pg

我开始安装所有这些依赖项:

sudo yum install ruby19 ruby19-devel gem rubygems19-devel make gcc postgresql9 postgresql9-devel postgresql9-server

然后我切换到root用户并运行

bundle install

我收到绿色成功消息:

Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

但是,当我cd到dir并运行

rails s -p80

我得到了所有这一切并且它无法启动(我仍然是root用户因为如果我不是root用户,绑定将不能用于端口80):

/usr/local/share/gems/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require': cannot load such file -- pg_ext (LoadError)
    from /usr/local/share/gems/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `block in require'
    from /usr/local/share/gems/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /usr/local/share/gems/gems/activesupport-3.2.8/lib/active_support/dependencies.rb:251:in `require'
    from /usr/local/share/gems/gems/pg-0.14.0/lib/pg.rb:4:in `<top (required)>'
    from /usr/local/share/gems/gems/bundler-1.2.0/lib/bundler/runtime.rb:68:in `require'
    from /usr/local/share/gems/gems/bundler-1.2.0/lib/bundler/runtime.rb:68:in `block (2 levels) in require'
    from /usr/local/share/gems/gems/bundler-1.2.0/lib/bundler/runtime.rb:66:in `each'
    from /usr/local/share/gems/gems/bundler-1.2.0/lib/bundler/runtime.rb:66:in `block in require'
    from /usr/local/share/gems/gems/bundler-1.2.0/lib/bundler/runtime.rb:55:in `each'
    from /usr/local/share/gems/gems/bundler-1.2.0/lib/bundler/runtime.rb:55:in `require'
    from /usr/local/share/gems/gems/bundler-1.2.0/lib/bundler.rb:128:in `require'
    from /home/user/TransForm/config/application.rb:7:in `<top (required)>'
    from /usr/local/share/gems/gems/railties-3.2.8/lib/rails/commands.rb:53:in `require'
    from /usr/local/share/gems/gems/railties-3.2.8/lib/rails/commands.rb:53:in `block in <top (required)>'
    from /usr/local/share/gems/gems/railties-3.2.8/lib/rails/commands.rb:50:in `tap'
    from /usr/local/share/gems/gems/railties-3.2.8/lib/rails/commands.rb:50:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

也许有一种简单的方法可以从一开始就正确地部署它而不是搞乱错误骰子?我需要PostgreSQL。这个应用程序可以在除AWS EC2实例之外的任何地方运行,所以我知道我的Gemfile是正确的。任何线索都会有所帮助。

2 个答案:

答案 0 :(得分:1)

打开irb&amp;类型require "pg"是否有效?如果没有,则检查pg_ext目录中是否存在/usr/local/share/gems/gems/pg-0.14.0/lib/。您可以使用

手动安装手动postgresql gem
gem install pg

如果仍然无效,请确保您使用的是最新版本的ruby&amp;最新版本的rubygems使用gem environment命令。如果是旧版本,您可以使用rvm安装最新版本

答案 1 :(得分:0)

        use gem pg 
            than 
             bundle install
             bundle update
               please not use any version of pg 
       I face this error and solved by this