title: Library not loaded: /usr/lib/libpq.5.dylib
body: <p>Recently came back to a computer (Mac OS X Lion 10.7) with which I've had repeated environment issues, started a new rails app, and ran </p>
  
  <pre><code>rake db:create
  </code></pre>
  
  <p>I got this error output (with --trace):</p>
  
  <pre><code>rake aborted!
  dlopen(/Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195/gems/pg-0.15.1/lib/pg_ext.bundle, 9): Library not loaded: /usr/lib/libpq.5.dylib
    Referenced from: /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195/gems/pg-0.15.1/lib/pg_ext.bundle
    Reason: image not found - /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195/gems/pg-0.15.1/lib/pg_ext.bundle
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195/gems/pg-0.15.1/lib/pg.rb:4:in `require'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195/gems/pg-0.15.1/lib/pg.rb:4:in `&lt;top (required)&gt;'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
  /Users/&lt;username&gt;/rails/&lt;appname&gt;/config/application.rb:7:in `&lt;top (required)&gt;'
  /Users/&lt;username&gt;/rails/&lt;appname&gt;/Rakefile:4:in `require'
  /Users/&lt;username&gt;/rails/&lt;appname&gt;/Rakefile:4:in `&lt;top (required)&gt;'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load_rakefile'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.1.0/lib/rake/application.rb:637:in `raw_load_rakefile'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.1.0/lib/rake/application.rb:94:in `block in load_rakefile'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.1.0/lib/rake/application.rb:93:in `load_rakefile'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.1.0/lib/rake/application.rb:77:in `block in run'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
  /Users/&lt;username&gt;/.rvm/gems/ruby-2.0.0-p195@global/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
  bin/rake:4:in `&lt;main&gt;'
  </code></pre>
  
  <p>config/application.rb:7 refers to:</p>
  
  <pre><code>Bundler.require(:default, Rails.env)
  </code></pre>
  
  <p>This comes on the heals of a couple environment issues that are, I'm sure, causing the issue, but I don't know how. Basically, I was having issues with homebrew (brew install wget wouldn't work, complaining it was already downloaded, but then saying:</p>
  
  <pre><code>checking for libssl... no
  configure: error: --with-ssl=openssl was given, but SSL is not available
  </code></pre>
  
  <p>So I uninstalled homebrew, uninstalled my shell (fish shell), reinstalled both, and tried to start things from scratch. Probably not a great idea, in retrospect. I seem to have messed things up worse than they already were. </p>
  
  <p>brew doctor seems to think most things are OK, though. The only thing that jumps out at me as possibly related is:</p>
  
  <pre><code>  /Users/sasha/.rvm/bin/pkg-config
  </code></pre>
  
  <p>(There's another thing brought up -- "/usr/bin occurs before /usr/local/bin", but this only applies to the node, npm, and gcov-4.2 installs, which don't seem relevant to this Rails issue.)</p>
  
  <p>And I think RVM is <em>supposed to</em> have its own pkg-config install, right?</p>
  
  <p>At any rate, OpenSSL is installed and updated by homebrew, and looking good (it shows up in brew list). Also, my XCode Command Line Tools is up to date as well. </p>
  
  <p>I guess my question is if anyone has any idea what's going on? I've tried reordering my path to comply with brew doctor, un/reinstalling lots of things, updating everything, etc, and this just won't go away. Super frustrating, cause I basically can't do anything without rake working. And I think this dylib and openssl issue might be interrelated, so I figured I'd just dump all this data here.</p>
  
  <p>Any ideas? I'd really appreciate help.</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT</strong> -- This is using Rails 4.0, with the pg gem.</p>
  
  <pre><code># Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
  gem 'rails', '4.0.0.rc1'
  
  # Use postgresql as the database for Active Record
  gem 'pg'
  </code></pre>
  
  <p>if that makes any difference.</p>
  
  <p><strong>UPDATE</strong> -- Seems to be related to <a href="https://stackoverflow.com/questions/17777864/configure-errror-library-crypto-is-required-for-openssl">this problem</a>, which I'm also having. I think rake is not working because of pg, which isn't working because of crpyto/openssl.</p>