Solution for bundle/gem install rmagick error: Can't find MagickWand.h

Tadashi Shigeoka ·  Thu, November 30, 2017

I’ll introduce the solution when an error occurs during gem install rmagick for installing Ruby’s image processing library RMagick.

Ruby | ルビー

The cause was that ImageMagick version 7 was too new. Downgrading it to version 6 allowed me to successfully install RMagick.

# cd to_rails_app_dir 
$ bundle install
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/your_user/works/your_app/vendor/bundle/ruby/2.4.0/gems/rmagick-2.16.0/ext/RMagick
/Users/your_user/.rvm/rubies/ruby-2.4.1/bin/ruby -r ./siteconf20171130-66060-5yh4gp.rb extconf.rb
checking for gcc... yes
checking for Magick-config... no
checking for pkg-config... yes
checking for outdated ImageMagick version (<= 6.4.9)... no
checking for presence of MagickWand API (ImageMagick version >= 6.9.0)... no
checking for Ruby version >= 1.8.5... yes
checking for stdint.h... yes
checking for sys/types.h... yes
checking for wand/MagickWand.h... no

Can't install RMagick 2.16.0. Can't find MagickWand.h.
*** 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=/Users/your_user/.rvm/rubies/ruby-2.4.1/bin/$(RUBY_BASE_NAME)

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /Users/your_user/works/your_app/vendor/bundle/ruby/2.4.0/extensions/x86_64-darwin-15/2.4.0/rmagick-2.16.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/your_user/works/your_app/vendor/bundle/ruby/2.4.0/gems/rmagick-2.16.0 for inspection.
Results logged to /Users/your_user/works/your_app/vendor/bundle/ruby/2.4.0/extensions/x86_64-darwin-15/2.4.0/rmagick-2.16.0/gem_make.out

An error occurred while installing rmagick (2.16.0), and Bundler cannot continue.
Make sure that `gem install rmagick -v '2.16.0'` succeeds before bundling.

In Gemfile:
  rmagick

At the time this error occurred, the installed ImageMagick version was 7.

$ identify -version
Version: ImageMagick 7.0.7-5 Q16 x86_64 2017-10-03 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules 
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff xml zlib

Installing ImageMagick 6

I’ll install ImageMagick 6 separately using Homebrew on macOS.

$ brew install imagemagick@6
$ brew link --overwrite --force imagemagick@6
Linking /usr/local/Cellar/imagemagick@6/6.9.9-24... 309 symlinks created

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"' >> ~/.zshrc
$ echo 'export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"' >> ~/.zshrc

After completing brew link and export PATH, check the version again. If you can confirm ImageMagick 6, you’re done.

$ identify -version
Version: ImageMagick 6.9.9-24 Q16 x86_64 2017-11-30 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules 
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff xml zlib

Example of brew link with various warnings

$ brew link --force imagemagick@6
Linking /usr/local/Cellar/imagemagick@6/6.9.9-24... 
Error: Could not symlink bin/Magick++-config
Target /usr/local/bin/Magick++-config
is a symlink belonging to imagemagick. You can unlink it:
  brew unlink imagemagick

To force the link and overwrite all conflicting files:
  brew link --overwrite imagemagick@6

To list all files that would be deleted:
  brew link --overwrite --dry-run imagemagick@6
$ brew link --overwrite imagemagick@6
Warning: imagemagick@6 is keg-only and must be linked with --force
Note that doing so can interfere with building software.

If you need to have this software first in your PATH instead consider running:
  echo 'export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"' >> ~/.zshrc

Run bundle install again

Once the setup to use ImageMagick 6 is complete, finally run bundle install. If it installs successfully, the work is complete.

# cd to_rails_app_dir 
$ bundle install

That’s all from the Gemba that wants to install RMagick with Ruby on Rails.

Reference Information