LoginSignup
17
9

More than 5 years have passed since last update.

Homebrewで特定バージョンのインストール (RMagick対処)

Last updated at Posted at 2017-08-15

TL;DR

Homebrewで簡単に過去バージョンのパッケージを導入してRMagickをインストール出来るようになる

brew install --build-from-source https://raw.githubusercontent.com/Homebrew/homebrew-core/6f014f2b7f1f9e618fd5c0ae9c93befea671f8be/Formula/imagemagick.rb

発生した問題

RMagick gem をインストールしようと思ったがエラーで入らない。

$ gem install rmagick
Building native extensions.  This could take a while...
ERROR:  Error installing rmagick:
    ERROR: Failed to build gem native extension.

    current directory: /Users/chanibarin/.anyenv/envs/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/rmagick-2.16.0/ext/RMagick
/Users/chanibarin/.anyenv/envs/rbenv/versions/2.3.1/bin/ruby -r ./siteconf20170815-15540-14avoah.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.4.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/chanibarin/.anyenv/envs/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/chanibarin/.anyenv/envs/rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-15/2.3.0-static/rmagick-2.16.0/mkmf.log

extconf failed, exit code 1

対処方法

ImageMagick6をインストールしないといけない

手順

  1. 既に入っているImageMagickをアンインストール
  2. 古いバージョンのImageMagickをインストール

ざっくりですがこの手順で進めます。
(ImageMagickが未インストールの方は1を飛ばしてOK)

1. 既に入っているImageMagickをアンインストール

下記コマンドを叩いて下さい

$ brew unlink imagemagick
$ brew remove imagemagick

2. 古いバージョンのImageMagickをインストール

  1. インストールしたいバージョンのハッシュを探す
    Homebrewのリポジトリからヒストリを遡ります
    https://github.com/Homebrew/homebrew-core/commits/master/Formula/imagemagick.rb


    該当の履歴を見つけたら、コミットハッシュをメモ



  2. メモしたハッシュを利用してパッケージを特定、インストール
    https://raw.githubusercontent.com/Homebrew/homebrew-core/6f014f2b7f1f9e618fd5c0ae9c93befea671f8be/Formula/imagemagick.rb

$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/6f014f2b7f1f9e618fd5c0ae9c93befea671f8be/Formula/imagemagick.rb
$ convert --version
Version: ImageMagick 6.9.7-3 Q16 x86_64 2017-01-07 http://www.imagemagick.org

3. 古いバージョンのImageMagickをインストール(--force使用)

--forceを使用する方法もあります

$ brew install imagemagick@6
$ brew link --force imagemagick@6

Rmagickインストール確認

上記手順にてImageMagick6を導入出来ればあとは入れるだけ!

$ gem install rmagick
Fetching: rmagick-2.16.0.gem (100%)
Building native extensions.  This could take a while...
Successfully installed rmagick-2.16.0
Parsing documentation for rmagick-2.16.0
Installing ri documentation for rmagick-2.16.0
Done installing documentation for rmagick after 5 seconds
1 gem installed

:thumbsup:

トラブルシューティング:ImageMagickでエラーが発生する場合

例えばこんなエラー

Magick::ImageMagickError: unable to load module `/usr/local/Cellar/imagemagick/6.9.7-3/lib/ImageMagick//modules-Q16/coders/png.la': file not found @ error/module.c/OpenModule/1302

--build-from-sourceをつけてインストールする

$ brew install --build-from-source https://raw.githubusercontent.com/Homebrew/homebrew-core/6f014f2b7f1f9e618fd5c0ae9c93befea671f8be/Formula/imagemagick.rb
17
9
0

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
17
9