So I ran into problems installing "mysql" and "sequel" for connecting to my localhost on my mac with Ruby. I fixed the issue by changing an environment variable on my mac but here was the original error.
> sudo gem install mysql -- --with-mysql-config=/path/to/mysql_config
> sudo gem install sequel
> ruby db-connect.rb
> /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require': LoadError: dlopen(/Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14/2.0.0/mysql-2.9.1/mysql/mysql_api.bundle, 9): Library not loaded: libmysqlclient.18.dylib (Sequel::AdapterNotFound)
Referenced from: /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14/2.0.0/mysql-2.9.1/mysql/mysql_api.bundle
Reason: image not found - /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-14/2.0.0/mysql-2.9.1/mysql/mysql_api.bundle
from /Library/Ruby/Site/2.0.0/rubygems/core_ext/kernel_require.rb:54:in `require'
So I started snooping around and I found a tidbit of code to put in my ~/.profile file
export DYLD_LIBRARY_PATH=/Applications/XAMPP/xamppfiles/lib:$DYLD_LIBRARY_PATH
And tada! It works. But if I fire up the terminal with this line uncommented in my bash profile, it spits out this line every time I run a ruby program:
> irb
sh: line 1: 16604 Trace/BPT trap: 5 xcode-select --print-path > /dev/null 2>&1
irb(main):001:0>
I am able to connect to the database and get information but I don't like that message. If I comment out the export line in my file and turn on a new terminal, the message disappears but then I am no longer able to connect to mysql and get the same AdapterNotFound for libmysqlclient.18.dylib
What's causing this message? How can I get rid of it or suppress it? Maybe there's a better way of doing this?
MacOSX Yosemite, latest XCode, ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14], ruby on rails
EDIT
gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.4.2
- RUBY VERSION: 2.0.0 (2014-05-08 patchlevel 481) [universal.x86_64-darwin14]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.0.0
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
- EXECUTABLE DIRECTORY: /usr/bin
- SPEC CACHE DIRECTORY: /Users/paulcarlton/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
- RUBYGEMS PLATFORMS:
- ruby
- universal-darwin-14
- GEM PATHS:
- /Library/Ruby/Gems/2.0.0
- /Users/paulcarlton/.gem/ruby/2.0.0
- /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /opt/local/bin
- /opt/local/sbin
- /usr/local/share/npm/bin
- /opt/local/php5/bin
- /opt/local/bin
- /opt/local/sbin
- /usr/local/bin
- /usr/bin
- /bin
- /usr/sbin
- /sbin
- /usr/local/git/bin
- /usr/local/MacGPG2/bin
- /usr/texbin
- /Applications/XAMPP/xamppfiles/htdocs/Development/adt-bundle-mac-x86_64-20140702/sdk/tools
Which ruby:
/usr/bin/ruby
sudo gem...
. sudo
at all if working with Rubies or gems managed by either app. sudo
temporarily raises your privileges to those of root, which won't know about your local Ruby installation, and again will install over Apple's Ruby.I keep this bash script on my machine to make it easier to get the MySQL gem installed:
#!/bin/sh -x MYSQL_PATH=/usr/local/mysql/bin LOCAL_MYSQL_LIB=/usr/local/lib/libmysqlclient.18.dylib MYSQL_LIB=/usr/lib/`basename $LOCAL_MYSQL_LIB` [ -f $LOCAL_MYSQL_LIB ] || echo "Can't find $LOCAL_MYSQL_LIB" && exit [ -f $MYSQL_LIB ] || echo "Linking $MYSQL_LIB to $LOCAL_MYSQL_LIB" && sudo ln -s $LOCAL_MYSQL_LIB $MYSQL_LIB PATH=$PATH:$MYSQL_PATH env ARCHFLAGS="-arch x86_64" gem install mysql2 -- --with-mysql-config=$MYSQL_PATH/mysql_config
You can modify that for your own use.