Rails 服务器无法使用 rvm & 启动 mysql2 OSX 10.6.5 上的 ruby 1.9.2-p0
当我启动 Rails 服务器时,出现以下错误:
$ rails server
/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2.rb:7:in `require': dlopen(/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
Referenced from: /Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2- 0.2.6/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-
0.2.6/lib/mysql2/mysql2.bundle
在 rvm use ruby-1.9.2-p0 命令之后,我使用以下命令安装了 mysql2:
$ gem install mysql2 -- --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions. This could take a while...
Successfully installed mysql2-0.2.6
1 gem installed
Installing ri documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known
Installing RDoc documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known
我的 Gemfile 以及 database.yml 文件中都有 mysql2捆绑安装完成得很好
$ bundle show mysql2
/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6
我知道 Rails 服务器错误是由于它不知道 OSX 上的 mysql_config 位置,但是在 gem install 上我指定了正确的位置。然而,RVM 的 gem 似乎并不尊重 mysql_config 位置。
有人有解决这个问题的办法吗?
I'm getting the following error when I start rails server:
$ rails server
/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2.rb:7:in `require': dlopen(/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6/lib/mysql2/mysql2.bundle, 9): Library not loaded: libmysqlclient.16.dylib (LoadError)
Referenced from: /Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2- 0.2.6/lib/mysql2/mysql2.bundle
Reason: image not found - /Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-
0.2.6/lib/mysql2/mysql2.bundle
I've installed mysql2 with the following command after the rvm use ruby-1.9.2-p0 command:
$ gem install mysql2 -- --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config
Building native extensions. This could take a while...
Successfully installed mysql2-0.2.6
1 gem installed
Installing ri documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known
Installing RDoc documentation for mysql2-0.2.6...
Enclosing class/module 'mMysql2' for class Client not known
I have mysql2 in my Gemfile as well as in the database.yml file and bundle install completes fine
$ bundle show mysql2
/Users/ssmith/.rvm/gems/ruby-1.9.2-p0/gems/mysql2-0.2.6
I understand the rails server error is due to it not knowing the mysql_config location on OSX, however on gem install I specified the correct location. Yet RVM's gem is not respecting that mysql_config location it seems.
Anyone have a solution to this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
问题来自于 mysql2 gem 缺少 MySQL 的动态库。
比 install_name_tool ... 更干净的解决方案需要更新 DYLD_LIBRARY_PATH 来向其中添加 MySQL 库。为此,请更新您的
~/.bash_profile
以添加 MySQL 库文件夹:export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
注意:您可能想要根据您的安装更新 MySQL 位置,
这应该保持干净,但也确保任何需要 MySQL 动态库的 gem 或代码都能找到它们。
参考:http://lightyearsoftware.com/2011/ 02/mysql-5-5-on-mac-os-x/
2012 年 7 月参考更新: OS X 10.8 中的更改使得上面的简单方法不太优雅。如果设置该变量,则每次运行 setuid 或 setgid 程序时,您都会在 stderr 上收到此警告:
使用 Phusion Passenger Standalone 的 Ruby 开发人员将每五秒在其控制台中看到此消息。它变得非常令人恼火,速度非常快。
我已向 Apple 提交了错误。 OpenRadar 也有。
同时,还有第三种方法可以修复客户端库路径问题,不需要设置 DYLD_LIBRARY_PATH (解决此 10.8 问题)或使用 install_name_tool 破解 .bundle 文件:
The problem comes from the mysql2 gem missing the dynamic library from MySQL.
A cleaner solution than
install_name_tool ...
would need to update yourDYLD_LIBRARY_PATH
to add MySQL libs to it. To do so, update your~/.bash_profile
to add the MySQL library folder :export DYLD_LIBRARY_PATH="/usr/local/mysql/lib:$DYLD_LIBRARY_PATH"
Note: You might want to update the MySQL location based on your install
This should keep things clean but also ensure that any gem or code requiring MySQL dynamic libraries will find them.
Reference : http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/
Reference Update July 2012: A change in OS X 10.8 makes the easy method above less elegant. If you set that variable, every time you run a setuid or setgid program, you get this warning on stderr:
Ruby developers using Phusion Passenger Standalone will see this message displayed in their console every five seconds. It gets really irritating, very fast.
I have filed a bug with Apple. It’s also at OpenRadar.
In the meantime, there is also a third way to fix the client library path problem that doesn’t require setting DYLD_LIBRARY_PATH (working around this 10.8 issue) or hacking .bundle files with install_name_tool:
我在这里找到了答案: Mysql 5.5 、雪豹和铁轨
I found the answer here: Mysql 5.5, Snow leopard and rails
在 OS X 10.8 (Mountain Lion) 上,列出的答案都有问题,如答案和评论中所述。
install_name_tool
破解 gem 二进制文件每次都需要重做的地方gem 已安装或升级。brew
的mysql可能无法工作;无论如何,我不想重新配置已经工作的安装一个更简单、更强大的解决方案恕我直言,是将库的链接放在默认的动态库搜索路径中,该路径方便地包括
/usr/local/lib
。那是:On OS X 10.8 (Mountain Lion), the listed answers all have issues, as noted in the answers and comments.
DYLD_LIBRARY_PATH
to include /usr/local/mysql/lib gives warnings from OS X and from brewinstall_name_tool
to hack where the gem binary looks would need to be redone each time the gem is installed or upgraded.brew
's mysql may not work; and in any case I don't want to reconfigure an already-working installationA simpler and robust solution IMHO is to put a link to the library in the default dynamic library search path, which conveniently includes
/usr/local/lib
. That is:比尔,
弗雷德里克的答案将解决这个问题,但是您可能必须根据版本以及系统上的命名方式更改命令中的某些项目。
例如,在最新版本的 mysql 上 libmysqlclient.16.dylib 实际上是 libmysqlclient.18.dylib。尝试执行以下操作:
如果没有返回路径,您可以转到:
查找文件。然后只需输入 PWD 即可找到该命令的正确目录。
您还需要确定已安装的 rubies 的实际包名称是什么。您可以通过使用找到它
例如,我安装的 1.9.2 是 ruby-1.9.2.p180,而不是 ruby-1.9.2p0。这也需要在 Frederics 命令中进行更改。
因此,对我来说 Frederic 的命令分别是修复 1.8.7 和 1.9.2 的 rvm rubies:
Bill,
Frederic's answer will solve this problem, however you may have to change some of the items in the command depending on versions and how things are named on your system.
For example, on the most recent version of mysql libmysqlclient.16.dylib is actually libmysqlclient.18.dylib. Try doing a:
If that does not return the path you can go to:
to find the file. Then just a PWD to find the correct directory for the command.
You will also need to determine what the actual package names of the rubies you have installed are. You can find this by using
For example, my installation of 1.9.2 is ruby-1.9.2.p180, not ruby-1.9.2p0. This will need to be changed in Frederics command as well.
So, for me Frederic's command became for fixing the rvm rubies for 1.8.7 and 1.9.2, respectively:
以下通过: http://lightyearsoftware.com/2011 /02/mysql-5-5-on-mac-os-x/
2012 年 7 月更新:
OS X 10.8 中的更改使得上面的简单方法不太优雅。如果设置该变量,则每次运行 setuid 或 setgid 程序时,您都会在 stderr 上收到此警告:
使用 Phusion Passenger Standalone 的 Ruby 开发人员将每五秒在其控制台中看到此消息。它变得非常令人恼火,速度非常快。
我已向 Apple 提交了错误。 OpenRadar 也有。
同时,还有第三种方法可以修复客户端库路径问题,不需要设置 DYLD_LIBRARY_PATH (解决此 10.8 问题)或使用 install_name_tool 破解 .bundle 文件:
below via: http://lightyearsoftware.com/2011/02/mysql-5-5-on-mac-os-x/
Update July 2012:
A change in OS X 10.8 makes the easy method above less elegant. If you set that variable, every time you run a setuid or setgid program, you get this warning on stderr:
Ruby developers using Phusion Passenger Standalone will see this message displayed in their console every five seconds. It gets really irritating, very fast.
I have filed a bug with Apple. It’s also at OpenRadar.
In the meantime, there is also a third way to fix the client library path problem that doesn’t require setting DYLD_LIBRARY_PATH (working around this 10.8 issue) or hacking .bundle files with install_name_tool:
我在这个问题上停留了一段时间,并得出了不同的解决方案。
请注意缺少的库是版本 16:
原来我有该库的版本 20 -
libmysqlclient.20.dylib
我正确地在我的库中有
gem 'mysql2'
Gemfile,但我需要做的是卸载gem,gem uninstall mysql
(我安装了多个版本的gem),然后执行新的bundle install
来获取< em>正是我需要这个库的版本。之后,它查找并找到了该库的正确版本。
I was stuck on this for a while and came to a different solution.
Notice how the missing library is version 16:
Turns out I had version 20 of that library -
libmysqlclient.20.dylib
I correctly had
gem 'mysql2'
in my Gemfile, but what I needed to do was uninstall the gem,gem uninstall mysql
(I had multiple versions of the gem installed) and then doing a newbundle install
to get just the version I needed of this library.After that it looked for - and found - the correct version of that lib.
我的位于不同的位置,我必须使用:
Mine was in a different location, I had to use:
将 mysql 升级到最新版本并重新安装 mysql2 gem 对我有用
brew升级mysql
gem 卸载 mysql2
gem install mysql2
顺便说一句:我的MySQL版本是5.7.18,mysql2 gem版本是0.4.5
Upgraded mysql to latest version and reinstall mysql2 gem works to me
brew upgrade mysql
gem uninstall mysql2
gem install mysql2
BTW: My MySQL version is 5.7.18, mysql2 gem version is 0.4.5
这就是我所做的(与其他人类似)
Here is what I do (similar to others)