MySQL2宝石无法安装。

15

我一直在尝试在我的Ubuntu 12.04服务器上安装Gitlab很长时间了,一切进行得都很顺利,直到我运行bundle install

它提示无法安装MySQL2,但没有给出原因或纠正措施。

home/gitlab/gitlab$ sudo -u gitlab -H bundle install --deployment --without development test postgres
Fetching gem metadata from http://rubygems.org/.......
Fetching gem metadata from http://rubygems.org/..
Using rake (10.0.1) 
Using i18n (0.6.1) 
Using multi_json (1.3.7) 
Using activesupport (3.2.9) 
Using builder (3.0.4) 
Using activemodel (3.2.9) 
Using erubis (2.7.0) 
Using journey (1.0.4) 
Using rack (1.4.1) 
Using rack-cache (1.2) 
Using rack-test (0.6.2) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.2.1) 
Using actionpack (3.2.9) 
Using mime-types (1.19) 
Using polyglot (0.3.3) 
Using treetop (1.4.12) 
Using mail (2.4.4) 
Using actionmailer (3.2.9) 
Using arel (3.0.2) 
Using tzinfo (0.3.35) 
Using activerecord (3.2.9) 
Using activeresource (3.2.9) 
Using bundler (1.2.3) 
Using rack-ssl (1.3.2) 
Using json (1.7.5) 
Using rdoc (3.12) 
Using thor (0.16.0) 
Using railties (3.2.9) 
Using rails (3.2.9) 
Using acts-as-taggable-on (2.3.3) 
Using backports (2.6.5) 
Using bcrypt-ruby (3.0.1) 
Using blankslate (3.1.2) 
Using sass (3.2.3) 
Using bootstrap-sass (2.2.1.1) 
Using carrierwave (0.7.1) 
Using charlock_holmes (0.6.9) 
Using chosen-rails (0.9.8) 
Using coffee-script-source (1.4.0) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using coffee-rails (3.2.2) 
Using colored (1.2) 
Using daemons (1.1.9) 
Using orm_adapter (0.4.0) 
Using warden (1.2.1) 
Using devise (2.1.2) 
Using diff-lcs (1.1.3) 
Using draper (0.18.0) 
Using escape_utils (0.2.4) 
Using eventmachine (1.0.0) 
Using multipart-post (1.1.5) 
Using faraday (0.8.4) 
Using ffaker (1.15.0) 
Using sass-rails (3.2.5) 
Using font-awesome-sass-rails (2.0.0.0) 
Using foreman (0.60.2) 
Using gemoji (1.2.1) 
Using git (1.2.5) 
Using posix-spawn (0.3.6) 
Using yajl-ruby (1.1.0) 
Using pygments.rb (0.3.2) from https://github.com/gitlabhq/pygments.rb.git (at master) 
Using github-linguist (2.3.4) 
Using github-markup (0.7.4) 
Using gitlab_meta (4.0) 
Using gratr19 (0.4.4.1) 
Using grit (2.5.0) from https://github.com/gitlabhq/grit.git (at 7f35cb9) 
Using hashery (1.5.0) 
Using gitolite (1.1.0) 
Using grack (1.0.0) from https://github.com/gitlabhq/grack.git (at ba46f3b) 
Using hashie (1.2.0) 
Using multi_xml (0.5.1) 
Using rack-accept (0.4.5) 
Using rack-mount (0.8.3) 
Using virtus (0.5.2) 
Using grape (0.2.2) 
Using grit_ext (0.6.1) from https://github.com/gitlabhq/grit_ext.git (at 8e6afc2) 
Using haml (3.1.7) 
Using haml-rails (0.3.5) 
Using httparty (0.9.0) 
Using httpauth (0.2.0) 
Using jquery-atwho-rails (0.1.7) 
Using jquery-rails (2.1.3) 
Using jquery-ui-rails (2.0.2) 
Using jwt (0.1.5) 
Using kaminari (0.14.1) 
Using kgio (2.7.4) 
Using libv8 (3.3.10.4) 
Using modernizr (2.6.2) 
Installing mysql2 (0.3.11) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/local/bin/ruby extconf.rb 
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
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/local/bin/ruby
    --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 /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11 for inspection.
Results logged to /home/gitlab/gitlab/vendor/bundle/ruby/1.9.1/gems/mysql2-0.3.11/ext/mysql2/gem_make.out
An error occurred while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.
root@Server:/home/gitlab/gitlab$

2
mkmf.log 文件显示了什么? - rudolph9
你安装了mysql-server吗? - apchester
这可能会有所帮助:https://dev59.com/2G445IYBdhLWcg3w9Ows - Zabba
4个回答

53

它告诉你一个通用的可能问题:

由于某种原因,可能是缺少必要的库和/或头文件,无法创建Makefile。查看mkmf.log文件以获取更多详细信息。您可能需要配置选项。

这是你的线索。

确保你已安装了MySQL客户端仓库以及相关的“devel”包。像Ruby、Python、Perl等语言需要安装库和头文件才能编译提供语言到驱动程序接口的本地模块。

此外,你需要mysql_config,可以通过以下方式进行安装:

sudo apt-get install libmysqlclient-dev

我使用我的Ubuntu虚拟机复制了您的问题,并在安装libmysqlclient-dev后解决了它。

它将mysql_config放置在/usr/bin/mysql_config中,同时gem install mysqlgem install mysql2都能够成功安装。


1
如果您在完全不同的服务器上安装了mysql,那么在运行rvm和rails的服务器上是否仍需要安装所有这些软件包呢? - JohnMerlino
MySQL、PostgreSQL或其他客户端/服务器应用程序由两个部分组成:客户端软件和服务器软件。如果您在另一台机器上并想编写代码与服务器通信,那么是的,您必须安装客户端代码。如果没有访问服务器的客户端驱动程序,您的代码将如何与服务器通信? - the Tin Man
1
我在我的MBP上遇到了同样的问题,但是你的答案帮助了我。在运行brew install mysql之后,我成功地运行了gem install mysql2 - shovavnik

12

谢谢,它起作用了,只需要添加一些额外的东西。

sudo apt-get install libmysqld-dev libmysqlclient-dev mysql-client

你说这个解决方案对你有用,但你没有勾选它?你能接受他的答案吗? - DutGRIFF

3

我在rails4中使用了这个解决方案来解决这个问题:(Ubuntu 12.04)

    1) Install MySQL from symptic manager just type "mysql-server-5.5" 
    2) use following command and install 
       sudo apt-get install mysql-client libmysqlclient-dev

0

如果您正在使用Windows 8+ x64,请查看此问题正文中提供的答案:

在Windows上安装MySQL2 Gem

编辑

为了让那些给我投反对票的人开心,我复制了链接问题的内容:

  1. 清理:您来到这里的原因可能是您一直在尝试安装此gem,但失败了,因此您需要进行一些清理工作:gem uninstall mysql2

  2. 下载适用于Windows的Ruby 2.0 64位版本:

http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.0.0-p353-x64.exe?direct

2. 运行安装程序。注意它安装到的目录,并确保它在用户路径中。前往
控制面板 > 系统和安全 > 系统 - 高级系统设置 > 环境变量

确保将ruby安装目录中的bin目录路径添加到LOCAL用户的PATH环境变量中(如果在SYSTEM Path环境变量中也可以)

  1. 下载Ruby 2 64位开发工具包:

http://cdn.rubyinstaller.org/archives/devkits/DevKit-mingw64-64-4.7.2-20130224-1432-sfx.exe

4. 运行安装程序并记下安装目录的位置。说明中提到,一旦安装完成,您需要运行devkitvars.bat文件来设置环境变量。但是这在Windows 8.1上不起作用。您需要重复第2点中描述的设置本地路径的步骤,以为本地用户设置路径环境变量,添加Ruby Dev Kit二进制目录和Ruby Dev Kit MinGW二进制目录。例如,如果Dev Kit安装在c:\ruby2devkit,并且您将Ruby2安装到C:\Ruby200-x64目录中,则需要编辑您的路径语句如下:
C:\Ruby200-x64\bin;C:\ruby2-devkit\bin;c:\ruby2-devkit\mingw\bin
5. 接下来,您需要安装MySQL连接器。请勿下载并运行自动安装程序。相反,请下载zip文件并解压缩它。记下您解压缩到的目录(假设您解压缩到c:\mysql-connector)。

http://dev.mysql.com/downloads/file.php?id=450612

  1. MySQL Connector 64位中包含的libmysql.lib与mingw64-gcc编译器不兼容。您需要生成mingw64兼容的libmysql.lib文件。

  2. 下载所需工具

    https://structure-svm-map.googlecode.com/files/svm-map-win.zip

  3. 将此文件解压缩到本地目录,假设您将其解压缩到c:\ svm-map

  4. 编辑PATH环境路径,如前所述,现在看起来像这样:

    C:\Ruby200-x64\bin;C:\ruby2-devkit\bin;c:\ruby2-devkit\mingw\bin;c:\svm-map;C:\svm-map\python-mingw-lib
    
  5. 生成新的mysql库:

    cd c:\mysql-connector\lib
    
    gendef.exe libmysql.dll
    
    dlltool -v --dllname libmysql.dll --def libmysql.def --output-lib libmysql.lib
    
    copy libmysql.dll C:\Ruby200-x64\bin
    
    copy libmysql.lib C:\Ruby200-x64\bin
    
  6. 按以下方式安装gem(请注意使用正斜杠而不是反斜杠,如果使用反斜杠将失败):

    gem install mysql2 --platform=ruby -- '--with-mysql-dir="C:/mysql-connector/"'
    
希望这可以帮到你,也希望有人能关注那些想在Windows 7/8.1上进行Ruby on Rails开发的用户。

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