---

こんにちは〜

macにRMagick をインストールする

macにRMagickをインストールしようとしたらちょっとハマったのでメモ

ハマった

imagemagickがインストールされていることを確認して、rmagicをインストールしようとしたらエラーになる。

$ brew info imagemagick
imagemagick: stable 7.0.8-25 (bottled), HEAD
Tools and libraries to manipulate images in many formats
https://www.imagemagick.org/
Not installed
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/imagemagick.rb
==> Dependencies
Build: pkg-config ✔
Required: freetype ✔, jpeg ✔, libheif ✘, libomp ✘, libpng ✔, libtiff ✔, libtool ✔, little-cms2 ✔, openexr ✘, openjpeg ✔, webp ✔, xz ✔
==> Options
--HEAD
    Install HEAD version
==> Analytics
install: 117,999 (30 days), 339,088 (90 days), 1,355,956 (365 days)
install_on_request: 82,425 (30 days), 234,559 (90 days), 885,463 (365 days)
build_error: 0 (30 days)

$ bundle install --path vendor/bundler
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using bundler 2.0.1
Fetching rmagick 3.0.0
Installing rmagick 3.0.0 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /Users/sakamoto/rmagick_sample/vendor/bundler/ruby/2.4.0/gems/rmagick-3.0.0/ext/RMagick
/Users/sakamoto/.rbenv/versions/2.4.3/bin/ruby -r ./siteconf20190226-78336-2q7jx6.rb extconf.rb
checking for clang... yes
checking for Magick-config... no
checking for pkg-config... yes
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'
to the PKG_CONFIG_PATH environment variable
No package 'MagickCore' found
checking for outdated ImageMagick version (<= 6.8.9)... *** 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
  --without-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/sakamoto/.rbenv/versions/2.4.3/bin/$(RUBY_BASE_NAME)

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

/Users/sakamoto/rmagick_sample/vendor/bundler/ruby/2.4.0/extensions/x86_64-darwin-17/2.4.0-static/rmagick-3.0.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /Users/sakamoto/rmagick_sample/vendor/bundler/ruby/2.4.0/gems/rmagick-3.0.0 for
inspection.
Results logged to
/Users/sakamoto/rmagick_sample/vendor/bundler/ruby/2.4.0/extensions/x86_64-darwin-17/2.4.0-static/rmagick-3.0.0/gem_make.out

An error occurred while installing rmagick (3.0.0), and Bundler cannot continue.
Make sure that `gem install rmagick -v '3.0.0' --source 'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  rmagick

解決法

ImageMagick Version 6.8.9 or later (6.×.x). Version 7 is NOT yet supported; ETA April 2019 ( https://github.com/rmagick/rmagick/pull/299 ). You can get ImageMagick from www.imagemagick.org.

RMagickはImageMagickの7系に対応していないようなので、6系を入れる。

$ brew install imagemagick@6

インストールすると↓が出てくるので、必要なコマンドを実行する。

imagemagick@6 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have imagemagick@6 first in your PATH run:
  echo 'export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"' >> ~/.bash_profile

For compilers to find imagemagick@6 you may need to set:
  export LDFLAGS="-L/usr/local/opt/imagemagick@6/lib"
  export CPPFLAGS="-I/usr/local/opt/imagemagick@6/include"

For pkg-config to find imagemagick@6 you may need to set:
  export PKG_CONFIG_PATH="/usr/local/opt/imagemagick@6/lib/pkgconfig"

==> Summary
🍺  /usr/local/Cellar/imagemagick@6/6.9.10-27: 1,525 files, 24.3MB
$ echo 'export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"' >> ~/.bash_profile
$ source ~/.bash_profile
$ export PKG_CONFIG_PATH="/usr/local/opt/imagemagick@6/lib/pkgconfig"

その後RMagickをインストールする

$ bundle install --path vendor/bundler
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using bundler 2.0.1
Fetching rmagick 3.0.0
Installing rmagick 3.0.0 with native extensions
Bundle complete! 1 Gemfile dependency, 2 gems now installed.
Bundled gems are installed into `./vendor/bundler`

できた🙌

参考