Error installing mysql2: Failed to build gem native extension

当gem install mysql 时报错:

gem install mysql
Fetching mysql-2.9.1.gem
Temporarily enhancing PATH for MSYS/MINGW...
Building native extensions. This could take a while...
ERROR:  Error installing mysql:
        ERROR: Failed to build gem native extension.

    current directory: D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/mysql-2.9.1/ext/mysql_api
D:/Ruby32-x64/bin/ruby.exe extconf.rb
checking for -llibmysql... 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=D:/Ruby32-x64/bin/$(RUBY_BASE_NAME)
        --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-libmysql-dir
        --without-libmysql-dir
        --with-libmysql-include
        --without-libmysql-include=${libmysql-dir}/include
        --with-libmysql-lib
        --without-libmysql-lib=${libmysql-dir}/lib
        --with-libmysqllib
        --without-libmysqllib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  D:/Ruby32-x64/lib/ruby/gems/3.2.0/extensions/x64-mingw-ucrt/3.2.0/mysql-2.9.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in D:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/mysql-2.9.1 for inspection.
Results logged to D:/Ruby32-x64/lib/ruby/gems/3.2.0/extensions/x64-mingw-ucrt/3.2.0/mysql-2.9.1/gem_make.out

解决:

Ubuntu/Debian:

sudo apt-get install libmysql-ruby libmysqlclient-dev

Red Hat/CentOS :

sudo yum install mysql-devel

Mac OS X:

brew install mysql

参考:https://stackoverflow.com/questions/3608287/error-installing-mysql2-failed-to-build-gem-native-extension

Captcha Code

0 笔记

分享笔记

Inline Feedbacks
View all notes