#FJMK blog

citrus+というバンドをやってます。 http://citrusplus.jp 平日昼間はインターネットの会社@紀尾井町でエンジニアやってます。

rmagickがうまく入らないときの解決方法メモ

Railsでbundle installする際、rmagickのインストールに失敗したので、解消方法をメモ。   ちなみにMac環境です。(他のOSでも同様の現象が置きた場合は似たような解決方法でいけると思います)

bundle installしたところ、以下のようなエラーが出た。

$ bundle install
Fetching gem metadata from https://rubygems.org/..........
Fetching version metadata from https://rubygems.org/..
Fetching dependency metadata from https://rubygems.org/.
Using rake 11.3.0
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.10.1
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.1.0
Using rack 1.6.5
Using mime-types-data 3.2016.0521
Using arel 6.0.3
Using debug_inspector 0.0.2
Using byebug 9.0.6
Using mimemagic 0.3.2
Using coderay 1.1.1
Using coffee-script-source 1.11.1
Using execjs 2.7.0
Using thor 0.19.4
Using concurrent-ruby 1.0.2
Using multi_json 1.12.1
Using method_source 0.8.2
Using mysql2 0.4.5
Using slop 3.6.0
Using bundler 1.14.3
Using rdoc 4.3.0


Your user account isn't allowed to install to the system RubyGems.
  You can cancel this installation and run:

      bundle install --path vendor/bundle

  to install the gems into ./vendor/bundle/, or you can enter your password
  and install the bundled gems to RubyGems using sudo.

  Password:
Installing rmagick 2.16.0 with native extensions
Using sass 3.4.22
Using tilt 2.0.5
Using tzinfo 1.2.2
Using nokogiri 1.6.8.1
Using rack-test 0.6.3
Using mime-types 3.1
Using binding_of_caller 0.7.2
Using coffee-script 2.4.1
Using uglifier 3.0.4
Using figaro 1.1.1
Using sprockets 3.7.0
Using pry 0.10.4
Using sdoc 0.4.2
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /private/var/folders/_1/ymtjc6z928g75q5f7s6qtzfc0000gn/T/bundler20170125-72556-zs166vrmagick-2.16.0/gems/rmagick-2.16.0/ext/RMagick
/Users/sotarofujimaki/.rbenv/versions/2.3.1/bin/ruby -r ./siteconf20170125-72556-abxlfk.rb extconf.rb --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
checking for clang... 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
    --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/sotarofujimaki/.rbenv/versions/2.3.1/bin/$(RUBY_BASE_NAME)

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

  /var/folders/_1/ymtjc6z928g75q5f7s6qtzfc0000gn/T/bundler20170125-72556-zs166vrmagick-2.16.0/extensions/x86_64-darwin-16/2.3.0-static/rmagick-2.16.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/folders/_1/ymtjc6z928g75q5f7s6qtzfc0000gn/T/bundler20170125-72556-zs166vrmagick-2.16.0/gems/rmagick-2.16.0 for inspection.
Results logged to /var/folders/_1/ymtjc6z928g75q5f7s6qtzfc0000gn/T/bundler20170125-72556-zs166vrmagick-2.16.0/extensions/x86_64-darwin-16/2.3.0-static/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.

エラーをみるに、rmagickのインストールに失敗してる模様。 rmagickだけ入れようとしてみたり、imagemagick入れ直したりしてみたけど上手く行かず色々試していた所、以下のページに到達。 Rails に ImageMagick が入らずに環境が完全に壊れた場合の対処法 - カッパでも分かるiOSアプリゲーム開発 (とても參考になりました。ありがとうございます。)

この方も色々試したみたいだけど、imagemagick7 と imagemagick6のファイルパス混同を解消したところ解決したよう。

自分も同様に

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

してimagemagick6を入れて、bundle installを再度おこなったところ、うまくインストールできた。