所以我遇到了安装问题" mysql"和"续集"使用Ruby连接到我的Mac上的本地主机。我通过更改我的mac上的环境变量来修复此问题,但这是原始错误。
> 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'
所以我开始窥探,我发现了一些代码放在我的〜/ .profile文件中
export DYLD_LIBRARY_PATH=/Applications/XAMPP/xamppfiles/lib:$DYLD_LIBRARY_PATH
tada!有用。但是,如果我在我的bash配置文件中取消注释此行并启动终端,则每次运行ruby程序时它都会吐出此行:
> irb
sh: line 1: 16604 Trace/BPT trap: 5 xcode-select --print-path > /dev/null 2>&1
irb(main):001:0>
我能够连接到数据库并获取信息,但我不喜欢这条消息。如果我在我的文件中注释掉导出行并打开一个新终端,消息就会消失,但是我不再能够连接到mysql并为libmysqlclient.18.dylib获取相同的AdapterNotFound
导致此消息的原因是什么?我该怎样摆脱它或压制它?也许还有更好的方法吗?
MacOSX Yosemite,最新的XCode,ruby 2.0.0p481(2014-05-08修订版45883)[universal.x86_64-darwin14],ruby on rails
修改
gem env
RubyGems环境:
- 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
哪个红宝石:
/usr/bin/ruby
答案 0 :(得分:0)
sudo gem...
发生。 sudo
。 sudo
暂时将您的权限提升为root用户的权限,root权限将不知道您的本地Ruby安装,并且将再次安装在Apple的Ruby上。我将这个bash脚本保存在我的机器上,以便更容易安装MySQL gem:
#!/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
您可以修改它以供自己使用。