Rails - Can't install RMagick 2.16.0. Can't find MagickWand.h

I appreciate this question has been asked many times before, however I've tried all available answers to no avail. The error log is as follows:

have_header: checking for wand/MagickWand.h... -------------------- no

"gcc -E -I/Users/mark/.rvm/rubies/ruby-2.3.3/include/ruby-2.3.0/x86_64-darwin16 -I/Users/mark/.rvm/rubies/ruby-2.3.3/include/ruby-2.3.0/ruby/backward -I/Users/mark/.rvm/rubies/ruby-2.3.3/include/ruby-2.3.0 -I.  -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/local/Cellar/imagemagick/7.0.4-8/include/ImageMagick-7  -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -I/usr/local/Cellar/imagemagick/7.0.4-8/include/ImageMagick-7  conftest.c -o conftest.i"
conftest.c:3:10: fatal error: 'wand/MagickWand.h' file not found
#include <wand/MagickWand.h>
     ^
1 error generated.
checked program was:
/* begin */
1: #include "ruby.h"
2: 
3: #include <wand/MagickWand.h>
/* end */

After running mdfind MagickWand.h I can see the path is:

/usr/local/Cellar/imagemagick/7.0.4-8/include/ImageMagick-7/MagickWand/MagickWand.h

I then run:

C_INCLUDE_PATH=/usr/local/Cellar/imagemagick/7.0.4-8/include/ImageMagick-7/MagickWand/ gem install rmagick

However get the same message as before.

Any help for how to get this solved is greatly appreciated.


Solution 1:

I have had the same issue for about a month, Mark (ever since the Imagemagick 7 update). I'm using homebrew on OSX Sierra.

For future visitors to this question, you can try linking and unlinking pkgconfig (brew unlink pkgconfig && brew link pkgconfig) or specifying the path as Mayur describes, but if those don't work you'll need to install Imagemagick 6 from source as Mark has done:

$ brew uninstall imagemagick
$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/6f014f2b7f1f9e618fd5c0ae9c93befea671f8be/Formula/imagemagick.rb

I believe the issue ultimately lies with pkgconfig, so when you see an update to pkgconfig, that should be the tipoff to try again.

Solution 2:

Worked this one for me at osx sierra

brew unlink imagemagick
brew install imagemagick@6 && brew link imagemagick@6 --force
echo 'export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"' >> ~/.bash_profile

Got it here RMagick installation: Can't find MagickWand.h

Solution 3:

Imagemagick 7 seems to not cooperate. Here is what I have found, it works for me:

brew update
brew rm imagemagick
brew install imagemagick@6
brew link imagemagick@6 --force
bundle

If you do not want to force link you can also do the following:

brew install imagemagick@6
PKG_CONFIG_PATH=/usr/local/opt/imagemagick@6/lib/pkgconfig gem install rmagick

per @Leo's comment

Please look at this GitHub Issue for more details.

Solution 4:

I had a similar issue with running

$ gem install rmagick

First of all, do you have imagemagick installed? If you're not sure, run

$ convert --version

If you do, you probably either installed it with fink or macports (maybe homebrew?). What is happening is that rvm can't find the imagemagick directory.

After reading https://superuser.com/questions/361435/i-have-compiled-imagemagick-on-my-centos-and-rmagick-wont-install I exported the imagemagick path by adding

$ export PKG_CONFIG_PATH="/opt/local/lib/pkgconfig:$PKG_CONFIG_PATH"

to my ~/.bash_profile, sourcing the new profile, then running gem install rmagick again.

It worked for me after I did this.