Ruby Gems: Missing libraries or headers

I need to install a Ruby gem on my Debian server. This fails with an error message which is not very helpful to me as a non-ruby programmer. Can you help me diagnose the problem? What are the “necessary libraries and/or headers” that are missing?

root ~ # gem install schleuder
Building native extensions.  This could take a while...
ERROR:  Error installing schleuder:
    ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb
checking for magic_open() in -lmagic... no
*** ERROR: missing required library to compile this module
*** 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:

Gem files will remain installed in /var/lib/gems/1.8/gems/ruby-filemagic-0.4.2 for inspection.
Results logged to /var/lib/gems/1.8/gems/ruby-filemagic-0.4.2/ext/gem_make.out

The logfile (assuming this is the right one) says:

  • Ruby gem installation stuck on Nokogiri
  • eventmachine on debian fails install via rubygems
  • Has anyone created a debian package for phusion passenger (aka mod_rails) that doesn't depend on rubygems?
  • Create a Debian package from a Ruby gem
  • Ruby - Gem - mysql - Failed to build gem native extension
  • The program 'rails' is currently not installed?
  • root ~ # cat /var/lib/gems/1.8/gems/ruby-filemagic-0.4.2/ext/mkmf.log
    have_library: checking for magic_open() in -lmagic... -------------------- no
    "gcc -o conftest -I. -I/usr/lib/ruby/1.8/x86_64-linux -I.    -fno-strict-aliasing -g -g -O2  -fPIC   conftest.c  -L. -L/usr/lib -L.  -rdynamic -Wl,-export-dynamic     -lruby1.8-static -lmagic  -lpthread -lrt -ldl -lcrypt -lm   -lc"
    conftest.c: In function ‘t’:
    conftest.c:3: error: ‘magic_open’ undeclared (first use in this function)
    conftest.c:3: error: (Each undeclared identifier is reported only once
    conftest.c:3: error: for each function it appears in.)
    checked program was:
    /* begin */
    1: /*top*/
    2: int main() { return 0; }
    3: int t() { void ((*volatile p)()); p = (void ((*)()))magic_open; return 0; }
    /* end */
    "gcc -o conftest -I. -I/usr/lib/ruby/1.8/x86_64-linux -I.    -fno-strict-aliasing -g -g -O2  -fPIC   conftest.c  -L. -L/usr/lib -L.  -rdynamic -Wl,-export-dynamic     -lruby1.8-static -lmagic  -lpthread -lrt -ldl -lcrypt -lm   -lc"
    /usr/bin/ld: cannot find -lmagic
    collect2: ld returned 1 exit status
    checked program was:
    /* begin */
    1: /*top*/
    2: int main() { return 0; }
    3: int t() { magic_open(); return 0; }
    /* end */

  • Best practice for adding other language files in ruby project
  • Error when running Jekyll command
  • bundle install does not find my gem!
  • Setting classpath for org.jruby.Main?
  • How to extract information from a gem
  • How do I get a list of gems that are installed that have native extensions?
  • One Solution collect form web for “Ruby Gems: Missing libraries or headers”

    Some Ruby gems come with “native extensions”, meaning that they aren’t entirely written in Ruby, but contain bindings to some external libraries written in C. Often this is for performance reasons, or so as to use well-established libraries rather than reinventing the wheel.

    In your case it can’t compile the native extension because the header files are missing. You probably need to install the libmagic-dev Debian package. Something like

    sudo apt-get install libmagic-dev

    would do the trick, depending on your package manager!

    Ruby is the best programming language in the world - Ruby on Rails.