Skip to content

Instantly share code, notes, and snippets.

Created February 16, 2012 15:17
  • Star 43 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Install libmagic on Mac OS X via homebrew
$ brew install libmagic
$ brew link libmagic (if the link is already created is going to fail, don't worry about that)
$ env ARCHFLAGS="-arch x86_64" gem install ruby-filemagic -- --with-magic-include=/usr/local/include --with-magic-lib=/usr/local/lib/
Copy link

This saved my life today, thanks Emili! : )

Copy link

djvs commented Feb 11, 2014


Copy link

Worked like a champ, thanks for saving my sanity.

Copy link

sbonami commented Oct 25, 2014

Thanks for this!

Copy link

buru commented Nov 7, 2014

Thanks! It worked!

Copy link

Awesome. Thank you!

Copy link


Copy link

Thank a lot!!!!!

Copy link

for a specific version (0.6.3)

env ARCHFLAGS="-arch x86_64" gem install -v 0.6.3 ruby-filemagic -- --with-magic-include=/usr/local/include --with-magic-lib=/usr/local/lib/`

Copy link

you're great :)

Copy link

FreezzzFrank commented Nov 2, 2018

ths a lot!!

Copy link

even after installing libmagic, not able to find the file.

#include <Magick++.h>
1 error generated.
make: *** [cpp/src/hash.d] Error 1

Copy link

yotamaz commented Feb 9, 2019

Awesome. Thank you!

Copy link

what is required Mac OS version to install libmagic? I have 10.11 and received the following error when tried $ brew install libmagic:

curl: (7) Failed to connect to port 21: Connection refused
Error: An exception occurred within a child process:
DownloadError: Failed to download resource "libmagic"
Download failed:

Copy link

Awesome. Thanks for this!

Copy link

wzehui commented Apr 15, 2019

bingo! Thanks!

Copy link


Copy link

jdieg0 commented Aug 7, 2019

Perfect. Thanks! brew install libmagic did it.

Copy link

Awesome thanks.

Copy link

Thank you 🌮 Saved my day

Copy link

Work like a charm

Copy link

Thanks man!

Copy link

d-kahara commented Jun 5, 2020

Thanks!! 👍🏾

Copy link

Thank you very much!

Copy link

remino commented Jul 14, 2021

On macOS Big Sur 11.4, I had to do the following instead of the last line above:

gem install ruby-filemagic -v '0.7.2' --source '' -- --with-magic-include=/opt/homebrew/include --with-magic-lib=/opt/homebrew/lib/

Copy link


Copy link

If folks that come here have issues with the also excellent ruby-filemagic Ruby Gem, there exists ruby-magic Ruby Gem too, which has a bit more active development.

One can install it as a pre-built (native) Ruby Gem or as usual, in which case it should use bundled libmagic (as an alternative for requiring a system-wide or external one present).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment