Ruby: Problem Installing mysql2 rmagick?

By Xah Lee. Date:

Installing gem mysql2

Installing mysql2 (0.3.11) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /home/xah/.rvm/rubies/ruby-1.9.3-p327/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.
gem mysql2 error.

I got this error when gem install mysql2 -v '0.3.11'. How to fix?

You need to instal “libmysqlclient-dev - MySQL database development files”. Do sudo apt-get install libmysqlclient-dev.

“libmysqlclient18 - MySQL database client library” might also work but i haven't tried that.

Installing gem rmagick

Installing rmagick (2.13.1) with native extensions 
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /home/xah/.rvm/rubies/ruby-1.9.3-p327/bin/ruby extconf.rb 
checking for Ruby version >= 1.8.5... yes
extconf.rb:128: Use RbConfig instead of obsolete and deprecated Config.
checking for gcc... yes
checking for Magick-config... no
Can't install RMagick 2.13.1. Can't find Magick-config in /home/xah/.rvm/gems/ruby-1.9.3-p327/bin:/home/xah/.rvm/gems/ruby-1.9.3-p327@global/bin:/home/xah/.rvm/rubies/ruby-1.9.3-p327/bin:/home/xah/.rvm/bin:/home/xah/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/xah/.rvm/bin:/home/xah/.rvm/bin

*** 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
        --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=/home/xah/.rvm/rubies/ruby-1.9.3-p327/bin/ruby

Gem files will remain installed in /home/xah/.rvm/gems/ruby-1.9.3-p327/gems/rmagick-2.13.1 for inspection.
Results logged to /home/xah/.rvm/gems/ruby-1.9.3-p327/gems/rmagick-2.13.1/ext/RMagick/gem_make.out
An error occurred while installing rmagick (2.13.1), and Bundler cannot continue.
Make sure that `gem install rmagick -v '2.13.1'` succeeds before bundling.
gem install rmagick -v '2.13.1' error.

I got this error when gem install rmagick -v '2.13.1'. How to fix?

You need sudo apt-get install imagemagick libmagickwand-dev. Sample output:

◆ sudo apt-get install libmagickwand-dev 
[sudo] password for xah: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libbz2-dev libcgraph5 libdjvulibre-dev libexif-dev libgraphviz-dev libgvpr1
  libilmbase-dev libjasper-dev liblcms1-dev liblqr-1-0-dev libmagickcore-dev
  libopenexr-dev libwmf-dev libxdot4
Suggested packages:
  libwmf-doc
The following NEW packages will be installed:
  libbz2-dev libcgraph5 libdjvulibre-dev libexif-dev libgraphviz-dev libgvpr1
  libilmbase-dev libjasper-dev liblcms1-dev liblqr-1-0-dev libmagickcore-dev
  libmagickwand-dev libopenexr-dev libwmf-dev libxdot4
0 upgraded, 15 newly installed, 0 to remove and 0 not upgraded.
Need to get 5,748 kB of archives.
After this operation, 18.0 MB of additional disk space will be used.

If you have a question, put $5 at patreon and message me.

  1. Ruby Basics
  2. Doc Lookup
  3. Print Version String
  4. Unicode 💎
  5. Quote String
  6. Quote Long String
  7. Format String
  8. String Operations
  9. True, False
  10. “if then else”
  11. for, while, Loop
  12. List
  13. Loop Thru List
  14. Hash Table
  15. Function Optional Parameter
  16. Map f to List
  17. Complex Numbers
  18. Intro to Reading Ruby Doc: What's M, C, ::, # ?
  19. Predefined Global Variables
  20. What's RVM, Gem, Rake, Bundler, RDoc, ri, irb?