我有一些问题时,试图安装mysql2宝石为Rails。当我试图通过运行bundle install或gem install mysql2来安装它时,它会给我以下错误:
安装mysql2错误:错误:未能建立gem本地扩展。
我如何解决这个问题并成功安装mysql2?
我有一些问题时,试图安装mysql2宝石为Rails。当我试图通过运行bundle install或gem install mysql2来安装它时,它会给我以下错误:
安装mysql2错误:错误:未能建立gem本地扩展。
我如何解决这个问题并成功安装mysql2?
当前回答
我在我的mac上遇到了这个错误,我发现我需要从mysql 32位升级到mysql 64位才能让这个错误消失。我在英特尔macbook pro上运行OSX 10.6, ruby 1.9.2和rails3.0.0
我还需要安装xcode,以获得编译gem所需的诸如“make”之类的unix实用程序。
一旦这样做,我能够运行gem安装mysql和gem安装mysql2没有错误。
其他回答
我可以看到大多数人已经找到了这个问题的解决方案,这主要是由于但不限于丢失的软件包,这发生在我身上后,我已经清除mysql并重新安装它。我必须运行这个命令来解决我的问题:
安装libmysqlclient-dev
这个命令帮助我解决了我的问题
在ubuntu 20.04 LTS下,这是唯一的解决方案,一直为我工作:
sudo apt-get install ruby-mysql2
对我来说,这很有帮助:
$ export LDFLAGS="-L/usr/local/opt/openssl/lib"
$ export CPPFLAGS="-I/usr/local/opt/openssl/include"
然后:
gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/' -- --with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib
结果:
Building native extensions with: '--with-cppflags=-I/usr/local/opt/openssl/include --with-ldflags=-L/usr/local/opt/openssl/lib'
This could take a while...
Successfully installed mysql2-0.5.2
Parsing documentation for mysql2-0.5.2
Installing ri documentation for mysql2-0.5.2
Done installing documentation for mysql2 after 0 seconds
1 gem installed
请看这篇文章(警告:里面有日语)。
I got the gem built on Mac OS X 10.6.6 by 1) Ensuring the Developer tools package is installed 2) Downloading the current MySQL package (5.5.8 in my case) from Source 3) Installing the cmake tool from cmake.org 4) Following the instructions in section 2.11 of INSTALL-SOURCE from the mysql distribution files 5) sudo gem install mysql2 -- --srcdir=/usr/local/mysql/include The gem built successfully, but there are two errors in the documentation that rdoc and ri complain about. But now when I try to require 'mysql2' I get a
LoadError: no such file to load -- mysql2/mysql2
我希望我得到的错误是libmysqlclient.16。Dylib无法找到,因为我们在另一篇文章中找到了(搜索install_name_tool)。
我的$PATH有/usr/local/mysql在里面(这是我的源代码和构建文件所在的位置),所以我有点难住了。如果有人有什么想法,我会在睡了几个小时后再来看看。
解决方案仅适用于Mac OS X
如果你已经用自制软件安装了MySQL,对我来说有效的方法是卸载MySQL,然后通过MySQL网站(https://www.mysql.com/)安装MySQL社区版。
安装后,只需重新输入命令gem install mysql2,如果有必要,sudo gem install mysql2,如果你得到的权限被拒绝的问题。