LoginSignup
0
0

More than 1 year has passed since last update.

【Rails】ERROR: Can't install RMagick 4.2.5. Can't find the ImageMagick library or one of the dependent libraries.の対処法

Posted at

mac OS バージョン11.6
エディタ…VScode
Rails 6.0.4

やりたいこと

bundle installした時にエラーが出ないようにしたい

エラー内容

% bundle install
(省略)
Gem::Ext::BuildError: ERROR: Failed to build gem
native extension.

(省略)
ERROR: Can't install RMagick 4.2.5.
Can't find the ImageMagick library or one of the
dependent libraries.
Check the mkmf.log file for more detailed information.

(省略)
An error occurred while installing
rmagick (4.2.5), and Bundler cannot continue.

だいぶ端折りましたが、エラー文で文字が赤くなっている部分だけ抜粋しました。

原因

Can't install RMagick 4.2.5.
Can't find the ImageMagick library or one of the
dependent libraries.


(和訳)
RMagick4.2.5をインストールできません。
ImageMagickライブラリまたは依存ライブラリの1つが見つかりません。


よって原因は、「必要なライブラリがインストールされていない為」ということになります。

解決策

必要なライブラリを導入した後、再度gem installするだけです。
(↓こちらの記事が大変参考になりました。)
https://qiita.com/yukiweaver/items/52c45f442b9d9d59367e

順に実行していきます。

1.Homebrew で ImageMagick 6 と pkg-config をインストールする

$ brew install imagemagick@6
$ brew install pkg-config

2.環境変数 PKG_CONFIG_PATH を指定する

PATHの指定ですが、上記の % brew install imagemagick@6 コマンドの入力に成功した場合、下の方に以下のような説明が表示されるかと思います。

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

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"

これの一番最後の部分をそのまま実行してPATHを通します。以下を実行。

export PKG_CONFIG_PATH="/usr/local/opt/imagemagick@6/lib/pkgconfig"

3.gemコマンドで rmagick をインストールする

$ gem install rmagick

これで準備が整いましたので、Gemfileを以下のようにして、bundle install実行。

.Gemfile
gem 'carrierwave'
gem 'rmagick'
# bundle install

以上です。

0
0
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
0
0