在Ubuntu上安装mysql gem遇到的困难

51

我正在尝试安装mysql 2.8.1 gem。我将使用它来构建一个在Ubuntu 10.04上运行的Rails 2.0.2应用程序。我将使用Ruby 1.8.7版本。我已经安装了开发依赖项(其他gems)。但由于某些原因,我无法安装它。我无法确定如何修复它。请帮帮我!!

当我尝试安装它时,在终端中收到以下消息:

mohnish@pc146724-desktop:~/Downloads$ sudo gem install mysql-2.8.1.gem 
Building native extensions.  This could take a while...
ERROR:  Error installing mysql-2.8.1.gem:
    ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
    --with-opt-dir
    --without-opt-dir
    --with-opt-include
    --without-opt-include=${opt-dir}/include
    --with-opt-lib
    --without-opt-lib=${opt-dir}/lib
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/bin/ruby1.8
    --with-mysql-config
    --without-mysql-config
    --with-mysql-dir
    --without-mysql-dir
    --with-mysql-include
    --without-mysql-include=${mysql-dir}/include
    --with-mysql-lib
    --without-mysql-lib=${mysql-dir}/lib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mlib
    --without-mlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-zlib
    --without-zlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-socketlib
    --without-socketlib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-nsllib
    --without-nsllib
    --with-mysqlclientlib
    --without-mysqlclientlib
    --with-mygcclib
    --without-mygcclib
    --with-mysqlclientlib
    --without-mysqlclientlib


Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
mohnish@pc146724-desktop:~/Downloads$ 
谢谢您的帮助!!
4个回答

129

尝试以下操作,然后安装mysql gem:

sudo apt-get install libmysqlclient-dev 

如果那样还不够,请尝试像这样

 sudo apt-get install libmysqlclient-dev libmysqlclient16 ruby-dev

2
这里的ruby-dev软件包是可选的。 - xyzman
4
对我来说可行,但我根本不需要安装libmysqlclient*. - hobs
22
执行以下命令以安装libmysqlclient-dev和libmysqlclient18:sudo apt-get install libmysqlclient-dev libmysqlclient18 - Zoltan
3
对我来说有效的方法是,只安装 libmysqlclient - Charney Kaye

9

尝试这个,然后安装mysql gem:

sudo apt-get install libmysqlclient-dev libmysqlclient16

然后运行sudo gem install mysql,这个方法可行。

文档仍然无法正确安装(出现大量“没有定义”的错误,但这不是一个大问题)。


2
您应该按照错误提示的建议去查看mkmf.log文件!使用find /usr/lib/ruby/gems/1.8/gems/ -name mkmf.log命令搜索此文件。通常,这个错误信息出现是因为您忘记安装所需扩展的-dev包。因此,如果您想要安装mysql gem,您可能忘记先安装libmysqlclient14-dev。请执行apt-cache search | grep dev命令以查找相应的软件包。
更多信息请查看此链接

1
在我的情况下,我遇到了以下错误信息:
安装mysql(2.8.1)时发生错误,Bundler无法继续。在打包之前,请确保“gem install mysql -v'2.8.1'”成功。
我尝试了:gem install mysql -v'2.8.1',我得到了一个类似于您收到的错误消息。
我通过以下方式解决了它:
步骤(1):运行此命令:sudo apt-get install libmysqlclient-dev 步骤(2):安装mysql:gem install mysql -v 2.8.1
您应该会收到类似于这样的成功消息:
已成功安装mysql-2.8.1 为mysql-2.8.1安装ri文档 1个gem已安装
希望我的回答有所帮助。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接