Unable to install ruby-filemagic 0.7.1 on Mac even though libmagic has been installed

618 Views Asked by At

Unable to install ruby-filemagic 0.7.1 on Mac even though libmagic has been installed.

The error is like :

checking for main() in -lgnurx... no

checking for magic_open() in -lmagic... no

*** ERROR: missing required library to compile this module

* extconf.rb failed *

Almost all answers fo ruby-filemagic installation are the brew install libmagic. However, it doesn't work.

2

There are 2 best solutions below

0
On

A few hours were cost before I found the problem. Let me write down the cause and solution here :

cause:

my ruby ($HOME/.rbenv/versions/x.x.x/bin/ruby) was under the control of rbenv, however my bundler was controlled by old ruby (/usr/local/ruby) . The stupid bundler could not find the library for installing ruby_filemagic and wasted so much time.

solution:

$ rbenv exec gem install bundler $ rbenv rehash make bundler, gem, ruby under the same management.

Sorry for my poor English. I hope this may help more people.

0
On

In my case, on Monterey 12.0.1 helped this:

brew unlink libmagic && brew link libmagic

sudo chown -R $(whoami) $(brew --prefix)/* - in case you have Error: Permission denied @ rb_sysopen

gem install ruby-filemagic -v '0.7.2' --source 'https://rubygems.org/' -- --with-magic-include=/opt/homebrew/include --with-magic-lib=/opt/homebrew/lib/