Bundle Install Fails: Error loading Rubygems plugin after I deleted files - ruby-on-rails

I am new to Ruby and Rails and am trying to get through the Hartl rails web development tutorial. During the course of the tutorial, I installed homebrew. After running brew doctor, homebrew instructed me to delete a handful of files unless I had put them where they were at on purpose. I deleted them and brew doctor said I was all clear.
Now, further along in the tutorial I am trying to deploy an app to Heroku. But I've found out that my gemfile.lock file was never updated by bundle install. In fact, bundle install hadn't been working for me at all. The error output is below. It appears to be related to one of the files I deleted (I base this on the line Library not loaded: /opt/local/lib/libssl.1.0.0.dylib; I remember deleting that file).
How do I fix this? From my research, I think I need to reinstall something, but I can't figure out what. I installed Postgresql, but that did nothing.
Secondarily, was deleting all of those files a huge mistake? How can I get them back (I also can't scroll up enough in my Terminal to see their names)? Would homebrew have worked if I had left them alone even though brew doctor raised concerns about them?
Wyatts-MacBook-Pro:first_app Wyatt$ bundle installError loading RubyGems plugin "/Users/Wyatt/.rvm/gems/ruby-2.0.0-p247#global/gems/rubygems-bundler-1.2.2/lib/rubygems_plugin.rb": dlopen(/Users/Wyatt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/x86_64-darwin11.4.2/openssl.bundle, 9): Library not loaded: /opt/local/lib/libssl.1.0.0.dylib
Referenced from: /Users/Wyatt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/x86_64-darwin11.4.2/openssl.bundle
Reason: image not found - /Users/Wyatt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/x86_64-darwin11.4.2/openssl.bundle (LoadError)
/Users/Wyatt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': dlopen(/Users/Wyatt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/x86_64-darwin11.4.2/digest/sha1.bundle, 9): Library not loaded: /opt/local/lib/libssl.1.0.0.dylib (LoadError)
Referenced from: /Users/Wyatt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/x86_64-darwin11.4.2/digest/sha1.bundle
Reason: image not found - /Users/Wyatt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/x86_64-darwin11.4.2/digest/sha1.bundle
from /Users/Wyatt/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require'
from /Users/Wyatt/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/definition.rb:1:in `<top (required)>'
from /Users/Wyatt/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler.rb:148:in `definition'
from /Users/Wyatt/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/cli.rb:245:in `install'
from /Users/Wyatt/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/vendor/thor/task.rb:27:in `run'
from /Users/Wyatt/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/vendor/thor/invocation.rb:120:in `invoke_task'
from /Users/Wyatt/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/vendor/thor.rb:344:in `dispatch'
from /Users/Wyatt/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/vendor/thor/base.rb:434:in `start'
from /Users/Wyatt/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/bin/bundle:20:in `block in <top (required)>'
from /Users/Wyatt/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/lib/bundler/friendly_errors.rb:3:in `with_friendly_errors'
from /Users/Wyatt/.rvm/gems/ruby-2.0.0-p247#global/gems/bundler-1.3.5/bin/bundle:20:in `<top (required)>'
from /Users/Wyatt/.rvm/gems/ruby-2.0.0-p247#global/bin/bundle:23:in `load'
from /Users/Wyatt/.rvm/gems/ruby-2.0.0-p247#global/bin/bundle:23:in `<main>'
from /Users/Wyatt/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/bin/ruby_noexec_wrapper:14:in `eval'
from /Users/Wyatt/.rvm/gems/ruby-2.0.0-p247#railstutorial_rails_4_0/bin/ruby_noexec_wrapper:14:in `<main>'

Thanks to Nick Veys for this answer:
I just had to run brew reinstall openssl to replace the missing library.

Related

Ruby Library not loaded: #rpath/libicui18n.58.dylib

I'm running the command bundle exec rails canvas:compile_assets to install Canvas LMS on localhost. However, I get the following error
LoadError: dlopen(/Users/parzival/.rbenv/versions/2.6.7/lib/ruby/gems/2.6.0/gems/nokogiri-xmlsec-instructure-0.9.7/lib/nokogiri_ext_xmlsec.bundle, 9): Library not loaded: #rpath/libicui18n.58.dylib
Traceback:
LoadError: dlopen(/Users/parzival/.rbenv/versions/2.6.7/lib/ruby/gems/2.6.0/gems/nokogiri-xmlsec-instructure-0.9.7/lib/nokogiri_ext_xmlsec.bundle, 9): Library not loaded: #rpath/libicui18n.58.dylib
Referenced from: /Users/parzival/.rbenv/versions/2.6.7/lib/ruby/gems/2.6.0/gems/nokogiri-xmlsec-instructure-0.9.7/lib/nokogiri_ext_xmlsec.bundle
Reason: image not found - /Users/parzival/.rbenv/versions/2.6.7/lib/ruby/gems/2.6.0/gems/nokogiri-xmlsec-instructure-0.9.7/lib/nokogiri_ext_xmlsec.bundle
/Users/parzival/exempt/canvas/config/application.rb:38:in `<top (required)>'
/Users/parzival/exempt/canvas/Rakefile:6:in `require'
/Users/parzival/exempt/canvas/Rakefile:6:in `<top (required)>'
/Users/parzival/exempt/canvas/bin/rails:16:in `require'
/Users/parzival/exempt/canvas/bin/rails:16:in `<top (required)>'
/Users/parzival/exempt/canvas/bin/spring:20:in `require'
/Users/parzival/exempt/canvas/bin/spring:20:in `<top (required)>'
bin/rails:5:in `load'
bin/rails:5:in `<main>'
(See full trace by running task with --trace)
I tried to search for similar questions on StackOverflow but only found answers for Python/Conda Environment.
I'm using MacOS Big Sur 11.1 and Ruby 2.6.7. Node version 14.16.1 and npm version 6.14.12.
What I've Tried (Edit on April 29, 2021)
Reinstalling Node, PHP using Homebrew, and all other solutions specified in this GitHub post
Reinstalled yarn, npm, gem, bundle, rails, and all dependencies
Installing different versions of Node, (my system default is v16, I installed v14 for this project, also tried with v12)
Reinstalled the package from instructure and repeated installation process
Reinstalled nokogiri-xmlsec-instructure(which seems to be causing the error); tried different versions but none appeared to be compatible with other dependencies
run brew upgrade and many other commands to upgrade to the latest version
However, none of the above options I tried worked. The same error still persists.
As #Siguza mentioned requested in the comments, nothing returns when I run find /Users/parzival/.rbenv -name libicui18n.58.dylib. I also searched for this file on my device, but it's nowhere to be found.
Please let me know if you need any additional info - I'd be happy to provide them. Any help to fix this issue is greatly appreciated :)

Ruby on Rail 5.2 Can't start server. Lots of errors I don't understand

Working my way through a RoR tutorial. All was well until yesterday when I came across a bunch or errors that I can't understand. It looks like an openssl issue, but what I've read of that involves stuff I'm not using. I didn't add or update any gems. In fact, git shows no changes since my last commit which was working prior to yesterday. Any thoughts? What could have changed from one day to the next. I think the only thing I did was update postgresql using Homebrew. Might that have had some negative Thanks.
/usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': dlopen(/usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/x86_64-darwin17/digest/md5.bundle, 9): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (LoadError)
Referenced from: /usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/x86_64-darwin17/digest/md5.bundle
Reason: image not found - /usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/x86_64-darwin17/digest/md5.bundle
from /usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from /usr/local/lib/ruby/gems/2.5.0/gems/rubocop-0.54.0/lib/rubocop/processed_source.rb:3:in `<top (required)>'
from /usr/local/lib/ruby/gems/2.5.0/gems/rubocop-0.54.0/lib/rubocop.rb:613:in `require_relative'
from /usr/local/lib/ruby/gems/2.5.0/gems/rubocop-0.54.0/lib/rubocop.rb:613:in `<top (required)>'
from /usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from /usr/local/Cellar/ruby/2.5.0/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from /usr/local/lib/ruby/gems/2.5.0/gems/rubocop-0.54.0/bin/rubocop:6:in `<top (required)>'
from /usr/local/bin/rubocop:23:in `load'
from /usr/local/bin/rubocop:23:in `<main>'
looks like you need to install openssl
in macOS you can do it with brew install openssl and than install your gems again with brew install --force to make sure that the correct library path was used during the compilation
in case it won't work try installing openssl version 1.0 (since that's the version mention in the stacktrace) with brew install openssl#1.0 and then reinstalling your gems again
did you upgrade your OS? or did it happen by itself maybe?

Rmagick errors when running Rails S after upgrading to OSX Mavericks 10.9

I updated my osx to Mavericks 10.9 from 10.7, and since then I have been having issues running 'rails s'.
The issue is with Rmagick, and I have tried almost every solution that I could find. Most people recommended reinstalling imagemagick through homebrew, and reinstalling rmagick gem, but that didn't work. I even uninstalled homebrew as a whole, and reinstalled it. I tried getting rid of gemfile.lock, and running bundle install again, but none of these worked.
Here is the error message I get when I try running the rails local server:
Kibaeks-MacBook-Pro:onvard_saas kibaek$ rails s
/Users/kibaek/.rvm/gems/ruby-2.1.0#onvard/gems/rmagick-2.13.2/lib/rmagick.rb:11:in `require': dlopen(/Users/kibaek/.rvm/gems/ruby-2.1.0#onvard/extensions/x86_64-darwin-12/2.1.0-static/rmagick-2.13.2/RMagick2.bundle, 9): Library not loaded: /usr/local/lib/libMagickCore.5.dylib (LoadError)
Referenced from: /Users/kibaek/.rvm/gems/ruby-2.1.0#onvard/extensions/x86_64-darwin-12/2.1.0-static/rmagick-2.13.2/RMagick2.bundle
Reason: image not found - /Users/kibaek/.rvm/gems/ruby-2.1.0#onvard/extensions/x86_64-darwin-12/2.1.0-static/rmagick-2.13.2/RMagick2.bundle
from /Users/kibaek/.rvm/gems/ruby-2.1.0#onvard/gems/rmagick-2.13.2/lib/rmagick.rb:11:in `<top (required)>'
from /Users/kibaek/.rvm/gems/ruby-2.1.0#global/gems/bundler-1.5.1/lib/bundler/runtime.rb:76:in `require'
from /Users/kibaek/.rvm/gems/ruby-2.1.0#global/gems/bundler-1.5.1/lib/bundler/runtime.rb:76:in `block (2 levels) in require'
from /Users/kibaek/.rvm/gems/ruby-2.1.0#global/gems/bundler-1.5.1/lib/bundler/runtime.rb:72:in `each'
from /Users/kibaek/.rvm/gems/ruby-2.1.0#global/gems/bundler-1.5.1/lib/bundler/runtime.rb:72:in `block in require'
from /Users/kibaek/.rvm/gems/ruby-2.1.0#global/gems/bundler-1.5.1/lib/bundler/runtime.rb:61:in `each'
from /Users/kibaek/.rvm/gems/ruby-2.1.0#global/gems/bundler-1.5.1/lib/bundler/runtime.rb:61:in `require'
from /Users/kibaek/.rvm/gems/ruby-2.1.0#global/gems/bundler-1.5.1/lib/bundler.rb:131:in `require'
from /Users/kibaek/onvard_saas/config/application.rb:13:in `<top (required)>'
from /Users/kibaek/.rvm/gems/ruby-2.1.0#onvard/gems/railties-3.2.16/lib/rails/commands.rb:53:in `require'
from /Users/kibaek/.rvm/gems/ruby-2.1.0#onvard/gems/railties-3.2.16/lib/rails/commands.rb:53:in `block in <top (required)>'
from /Users/kibaek/.rvm/gems/ruby-2.1.0#onvard/gems/railties-3.2.16/lib/rails/commands.rb:50:in `tap'
from /Users/kibaek/.rvm/gems/ruby-2.1.0#onvard/gems/railties-3.2.16/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I had trouble with this as well on OS 10.9. I tried many things and this is what worked for me (after installing Xcode 5):
brew install libtool --universal
brew link libtool
Quick research just found the following with other users who also had success:
Stack Overflow: rmagick-error-after-installing-os-x-mavericks
TheKUnit Blog: RMagick errors running rake tasks os x maverick
Edit: Another possibility is that you have a different version of RMagick than the gem is looking for (possibly from the reinstall). Your log shows your gem is looking for /usr/local/lib/libMagickCore.5.dylib which I am guessing it cannot find. Do
ls /usr/local/lib/
and see if you can find that file. If not, a
gem pristine rmagick
may help if you haven't already tried it. In my case I have Core 6 in that folder and not 5.

Library not loaded: /usr/lib/libpq.5.dylib

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
rake db:create
I got this error output (with --trace):
rake aborted!
dlopen(/Users/<username>/.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/<username>/.rvm/gems/ruby-2.0.0-p195/gems/pg-0.15.1/lib/pg_ext.bundle
Reason: image not found - /Users/<username>/.rvm/gems/ruby-2.0.0-p195/gems/pg-0.15.1/lib/pg_ext.bundle
/Users/<username>/.rvm/gems/ruby-2.0.0-p195/gems/pg-0.15.1/lib/pg.rb:4:in `require'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195/gems/pg-0.15.1/lib/pg.rb:4:in `<top (required)>'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `each'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195/gems/bundler-1.3.5/lib/bundler/runtime.rb:70:in `block in require'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `each'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195/gems/bundler-1.3.5/lib/bundler/runtime.rb:59:in `require'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195/gems/bundler-1.3.5/lib/bundler.rb:132:in `require'
/Users/<username>/rails/<appname>/config/application.rb:7:in `<top (required)>'
/Users/<username>/rails/<appname>/Rakefile:4:in `require'
/Users/<username>/rails/<appname>/Rakefile:4:in `<top (required)>'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195#global/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195#global/gems/rake-10.1.0/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195#global/gems/rake-10.1.0/lib/rake/application.rb:637:in `raw_load_rakefile'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195#global/gems/rake-10.1.0/lib/rake/application.rb:94:in `block in load_rakefile'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195#global/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195#global/gems/rake-10.1.0/lib/rake/application.rb:93:in `load_rakefile'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195#global/gems/rake-10.1.0/lib/rake/application.rb:77:in `block in run'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195#global/gems/rake-10.1.0/lib/rake/application.rb:165:in `standard_exception_handling'
/Users/<username>/.rvm/gems/ruby-2.0.0-p195#global/gems/rake-10.1.0/lib/rake/application.rb:75:in `run'
bin/rake:4:in `<main>'
config/application.rb:7 refers to:
Bundler.require(:default, Rails.env)
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:
checking for libssl... no
configure: error: --with-ssl=openssl was given, but SSL is not available
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.
brew doctor seems to think most things are OK, though. The only thing that jumps out at me as possibly related is:
/Users/sasha/.rvm/bin/pkg-config
(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.)
And I think RVM is supposed to have its own pkg-config install, right?
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.
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.
Any ideas? I'd really appreciate help.
Thanks!
EDIT -- This is using Rails 4.0, with the pg gem.
# 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'
if that makes any difference.
UPDATE -- Seems to be related to this problem, which I'm also having. I think rake is not working because of pg, which isn't working because of crpyto/openssl.
The problem was based on an inexplicably empty libssl.dylib file. There was a backup (libssl.dylib.BAK), and I just overwrote the empty file with it and -- poof -- all the problems went away. No idea how that happened in the first place, but if anyone's having similar problems, I'd look for .BAK files in usr/lib/ and (if there are any) see if the associated files are empty.

Ruby on Rails / PostgreSQL - Library not loaded error when starting server

Heyo. I apologize in advance if this question has been answered in another thread. I've searched through the site but I didn't find an answer. However, the closest related issue was Ruby on Rails / PostgreSQL - Library not Loaded error when starting server- libq.5.dylib, but it was never resolved, and the answer doesn't help me.
I'm trying to get PostgreSQL running on my Mac OSX 10.6.8. I already have Ruby 1.9.3p392 and Rails 3.2.13 installed.
Since I've 10.6.8, and PostGresApp requires 10.7+, I tried installing PG using the manual installer (v9.2.3) available here: http://www.enterprisedb.com/products-services-training/pgdownload
I first installed it to its default path at: /Library/PostgreSQL/9.2/. I then installed the pg gem (PATH=$PATH:/Library/PostgreSQL/9.2/bin sudo gem install pg). When I tried rails s to launch my localhost, I got the error below.
After some reading, I guessed it might be a path error, so I removed the pg gem, and then used the postgresql uninstaller. I then reinstalled pg in /users/stewartmccoy/Library/PostgreSQL/9.2/...and then reinstalled the pg gem. But I still get the same error.
Any thoughts on how I might correctly install PostgreSQL and get my rails server running?
stewart-mccoys-macbook:footy_subs stewartmccoy$ rails s
/Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg.rb:4:in `require': dlopen(/Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg_ext.bundle, 9): Library not loaded: libpq.5.dylib (LoadError)
Referenced from: /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg_ext.bundle
Reason: image not found - /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg_ext.bundle
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg.rb:4:in `<top (required)>'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `each'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `block in require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `each'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.3.4/lib/bundler.rb:132:in `require'
from /Users/stewartmccoy/Code/footy_subs/config/application.rb:13:in `<top (required)>'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:53:in `require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:53:in `block in <top (required)>'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
stewart-mccoys-macbook:footy_subs stewartmccoy$ gem uninstall pgSuccessfully uninstalled pg-0.14.1
stewart-mccoys-macbook:footy_subs stewartmccoy$ PATH=$PATH:/users/stewartmccoy/Library/PostgreSQL/9.2/bin sudo gem install pg
Password:
Fetching: pg-0.14.1.gem (100%)
Building native extensions. This could take a while...
Successfully installed pg-0.14.1
1 gem installed
Installing ri documentation for pg-0.14.1...
Installing RDoc documentation for pg-0.14.1...
stewart-mccoys-macbook:footy_subs stewartmccoy$ rails s
/Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg.rb:4:in `require': dlopen(/Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg_ext.bundle, 9): Library not loaded: libpq.5.dylib (LoadError)
Referenced from: /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg_ext.bundle
Reason: image not found - /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg_ext.bundle
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/pg-0.14.1/lib/pg.rb:4:in `<top (required)>'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `each'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:70:in `block in require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `each'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.3.4/lib/bundler/runtime.rb:59:in `require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392#global/gems/bundler-1.3.4/lib/bundler.rb:132:in `require'
from /Users/stewartmccoy/Code/footy_subs/config/application.rb:13:in `<top (required)>'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:53:in `require'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:53:in `block in <top (required)>'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:50:in `tap'
from /Users/stewartmccoy/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.13/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
The key part of the error is:
Library not loaded: libpq.5.dylib (LoadError)
This suggests that ruby can't find libpq at runtime. To address that you should probably set the DYLD_LIBRARY_PATH environment variable to point to the lib directory of your PostgreSQL install, either globally or in a wrapper script you use to start Rails. See this superuser question for some more info.
The Pg gem can find the library during compilation and installation because the pg_config executable is on the PATH and it uses that to find libpq. It appears that it doesn't store the path for use at runtime so you have to set the runtime dynamic linker up yourself.
A simple wrapper script (in case you don't want to modify your global environment) is something like:
#!/bin/bash
export DYLD_LIBRARY_PATH=/path/to/pg/lib
exec rails "$#"
The "$#" basically means "pass all arguments to this script through as if they were passed here directly". It preserves quoting correctly and essentially means that the rails command can't tell you didn't run it directly.
I wanted to put my two cents here to answers above.
Sometimes it's enough to just reinstall pg gem.
gem uninstall pg && gem install pg
In my case I upgraded postgresql server from 9.6 up to 14.x and dylib paths were changed.
/opt/local/lib/postgresql96/libpq.5.dylib -> /opt/local/lib/postgresql14/libpq.5.dylib
The gem uses pg_config to determine paths to /opt/local/lib/postgresql[version] folder (named PKGLIBDIR). To build native library for the gem rake sets paths to dynamic libs by fetching them from pg_config in compile. Once pg gem is compiled the paths are linked forever. So, the reinstallation recompiles and relinks path to the new libraries.
A similar stackoverflow answer proposed removing Postgres.app from your PATH, uninstalling the pg gem, and installing the pg gem again.
(I'm not taking the time to check carefully if that applies to this problem, but it solved a problem I had and I want to spread that solution around since I had trouble finding it.)

Resources