When upgrading PostgreSQL on your machine, previously installed versions of the pg
Rubygem will complain because their native extensions were compiled against an older version of Postgres. The error will look like this:
[daley (qa)]$ be rake db:create
rake aborted!
LoadError: dlopen(/opt/rubies/2.3.1/lib/ruby/gems/2.3.0/gems/pg-0.18.4/lib/pg_ext.bundle, 9): Library not loaded: /opt/boxen/homebrew/lib/libpq.5.5.dylib
Referenced from: /opt/rubies/2.3.1/lib/ruby/gems/2.3.0/gems/pg-0.18.4/lib/pg_ext.bundle
Reason: image not found - /opt/rubies/2.3.1/lib/ruby/gems/2.3.0/gems/pg-0.18.4/lib/pg_ext.bundle
/Users/pjkelly/src/daley/config/application.rb:7:in `<top (required)>'
The solve can be pretty simple - I've seen it work two different ways.
The first way to try is just uninstall the pg
gem and then re-install it - that should cause the gem to be built against the newer version of Postgres on your machine.
gem uninstall pg
bundle install
If that doesn't work, then the second option is a little more involved. First, comment out the line in your Gemfile that says gem 'pg'
. Next run the following:
bundle install --clean
That will remove all gems currently cached that are not specified in your Gemfile. Then uncomment gem 'pg'
in your Gemfile and re-bundle:
bundle install
Alternatively, I've found this works:
The first line in my example is where homebrew installs Peter Eisentraut's postgresql tap, other installs may vary.