我有一些问题时,试图安装mysql2宝石为Rails。当我试图通过运行bundle install或gem install mysql2来安装它时,它会给我以下错误:

安装mysql2错误:错误:未能建立gem本地扩展。

我如何解决这个问题并成功安装mysql2?


当前回答

对于MacOS Mojave:

——with-cppflags=-I/usr/local/opt/openssl/include . gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib——with-cppflags=-I/usr/local/opt/openssl/include

其他回答

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在里面(这是我的源代码和构建文件所在的位置),所以我有点难住了。如果有人有什么想法,我会在睡了几个小时后再来看看。

我也得到了这个错误。通过安装开发包来解决。我使用arch,它是:

sudo pacman -S base-devel

安装:

m4, autoconf, automake, bison, fakeroot, flex, libmpc, ppl, cloog-ppl, elfutils, gcc,
libtool, make, patch, pkg-config

但我认为它实际上需要make和gcc。错误输出说(在我的机器上,等等):

“你必须先安装开发工具。”

所以这是一个显而易见的决定,而且很有帮助。

在ubuntu 20.04 LTS下,这是唯一的解决方案,一直为我工作:

sudo apt-get install ruby-mysql2

在Ubuntu (18.04)

我能够通过运行以下程序来解决这个问题:

sudo apt-get install build-essential libmysqlclient-dev
gem install mysql2

参考

在纠正了mysql-dev问题之后,您可能需要删除坏的mysql2安装。仔细查看$ bundle安装后的消息。你可能需要

rm -rf vendor/cache/
rm -rf ./Zentest

这将清除坏的mysql2安装,以便最终的$ bundle安装可以创建一个好的安装。