Error installing mysql2: Failed to build gem native extension

后端 未结 27 2801
清酒与你
清酒与你 2020-11-22 08:06

I am having some problems when trying to install mysql2 gem for Rails. When I try to install it by running bundle install or gem install mysq

相关标签:
27条回答
  • 2020-11-22 08:51

    In my case this helped:

    $ export LDFLAGS="-L/usr/local/opt/openssl/lib"
    $ export CPPFLAGS="-I/usr/local/opt/openssl/include"
    

    Then:

    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
    

    Result:

    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
    

    See this post (WARNING: Japanese language inside).

    0 讨论(0)
  • 2020-11-22 08:54

    I had this issue on Windows 7. This is apparently an incompatibility issue and the solution is as follows:

    Download the libmySQL.dll file from an older InstantRails installer. It is available from the InstantRails GitHub repo.

    Next, copy that file into your Ruby/bin folder.

    Now, you are good to go ;)

    0 讨论(0)
  • 2020-11-22 08:55

    I'm on a mac and use homebrew to install open source programs. I did have to install mac Dev tools in order to install homebrew, but after that it was a simple:

    brew install mysql
    

    to install mysql. I haven't had a mysql gem problem since.

    0 讨论(0)
  • 2020-11-22 08:55

    I was running into this error on my mac and found that I needed to upgrade from mysql 32bit to mysql 64 bit to get this error to go away. I was running OSX 10.6 on an intel macbook pro with ruby 1.9.2 and rails3.0.0

    I also needed to install xcode in order to get unix utilities like "make" that are required to compile the gem.

    once this was done I was able to run gem install mysql and gem install mysql2 without error.

    0 讨论(0)
  • 2020-11-22 08:56

    On Ubuntu/Debian and other distributions using aptitude:

    sudo apt-get install libmysql-ruby libmysqlclient-dev
    

    Package libmysql-ruby has been phased out and replaced by ruby-mysql. This is where I found the solution.

    If the above command doesn't work because libmysql-ruby cannot be found, the following should be sufficient:

    sudo apt-get install libmysqlclient-dev
    

    On Red Hat/CentOS and other distributions using yum:

    sudo yum install mysql-devel
    

    On Mac OS X with Homebrew:

    brew install mysql
    
    0 讨论(0)
  • 2020-11-22 08:56

    I got this error too. Solved by installing development packages. I'm using arch and it was:

    sudo pacman -S base-devel
    

    which installed:

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

    but I think it actually needed make and gcc. Error output said (on my machine, among other):

    "You have to install development tools first."

    So it was an obvious decision and it helped.

    0 讨论(0)
提交回复
热议问题