LoginSignup
144
103

More than 5 years have passed since last update.

bundle install "rmagick" でインストールができない

Last updated at Posted at 2017-02-08

結論から言うと...

Imagemagickのバージョンを6に下げると、インストールできるようになる。

RMagickはImagemagickのバージョン7に対応していない模様。
RMagickを使用するには、ImageMagickという画像変換ツールをパソコン内にインストールする必要があるが、
「brew install imagemagick」でImagemagickをインストールするとバージョンは7になってしまうので注意。
既にに入っているバージョンが7の場合は、バージョンを下げましょう。

rmagickインストール関係で参考になるQiita記事リンクを最後にまとめました。
本記事のエラー以外で躓いている方は、そちらをご参照ください。

環境

macOS Sierra: 10.12.2
Ruby: 2.3.1
Rails: 5.0.1

bundle install "rmagick"で、gemをインストールできない...

Railsにて簡易チャットアプリを作成中。
画像投稿機能を実装するために、rmagickをインストールしようとしたところ、ターミナルに以下のエラー文が表示された。

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

current directory:
/Users/sho012b/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rmagick-2.16.0/ext/RMagick
/Users/sho012b/.rbenv/versions/2.3.1/bin/ruby -r ./siteconf20170208-64308-1vjup4v.rb extconf.rb
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/sho012b/.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:

/Users/sho012b/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.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
/Users/sho012b/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rmagick-2.16.0 for inspection.
Results logged to
/Users/sho012b/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.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.

解決方法

1. ImageMagick(バージョン7)をアンインストール
brew uninstall imagemagick
すでにインストールされているImageMagick(バージョン7)をアンインストール

2. ImageMagick(バージョン6)をインストール
brew install imagemagick@6
もしくは以下でもできるそう。
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/6f0‌​14f2b7f1f9e618fd5c0a‌​e9c93befea671f8be/Fo‌​rmula/imagemagick.rb
(私はこれではうまくいきませんでした。)

インストールが成功すると、ターミナルに以下のメッセージが。

This formula is keg-only, which means it was not symlinked into /usr/local.

Older version of imagemagick

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

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/imagemagick@6/lib
    CPPFLAGS: -I/usr/local/opt/imagemagick@6/include
For pkg-config to find this software you may need to set:
    PKG_CONFIG_PATH: /usr/local/opt/imagemagick@6/lib/pkgconfig

This formula is keg-only, which means it was not symlinked into /usr/local.
最初のこのメッセージが大事そうですね。

*"keg-only"とは

What does keg-only mean?
It means the formula is installed only into the Cellar, it is not linked into /usr/local. This means most tools will not find it. We don’t do this for stupid reasons. You can link the formula in still if you need to with brew link.(Github FAQ)

CellarにしかインストールされてないからLocalにはリンクされてないよ。多分このままだと使えないね。必要あればbrew linkしてね。みたいな感じでしょうか。うーん、Homebrewのことをまだ全然知らないので、今後調べる必要がありそうです。とりあえず現段階では「このままだと使えないからbrew linkせい!」と言う理解で留めておきます。

3.brew linkする
インストールは済んだものの、このままではImagemagickが"keg-only"と言う状態なので、以下のコマンドを実行。
brew link --force imagemagick@6

*linkとは
パッケージの有効化・無効化を行うコマンド

$ brew link <パッケージ名> #有効化
$ brew unlink <パッケージ名> #無効化

*--forceとは
上書きでインストールするコマンド?

4. RMagickのインストール
1~3を実行すると、Rmagickがインストールできるようになりました。

本エラーに対する参考リンク

GitHub Homebrew
Qiita 「SierraにRMagickを入れる」
Qiita「rmagickのインストールにハマった」
stackoverflow "ImageMagick 7 with RMagick 2.16 on MacOS Sierra Can't find MagickWand.h"

その他のRMagickインストール関連エラーQiita参考記事

RMagickのインストールで多くの人がエラーに苦しんでいるようですね...
以下ざっくりとカテゴリー分けしリンクをまとめました。本記事エラー以外のエラーでお困りの方は参考にしてみてください。
▪️pkg-config関連
rmagickのインストールでコケたのでメモ
MacでRmagickをインストール
gem install rmagickで失敗する。
▪️MagickWand.h関連
RMagickのインストールでエラー
▪️CentOS関連
gem install rmagickでchecking for Magick-config... noがでる解決方法
ImageMagick を標準パス以外にインストールしたら...
▪️brew以外でインストール
MacでImageMagickをインストール
gem install rmagick でインストール失敗
▪️Port関係
rmagickのインストールに失敗する場合

144
103
6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
144
103