コレグレーデギネード

WindowsとかUbuntuとかRubyとかRailsとか

rmagickをbundle installしようとしてエラー An error occurred while installing rmagick (4.0.0), and Bundler cannot continue. Make sure that `gem install rmagick -v '4.0.0' --source 'https://rubygems.org/'` succeeds before bundling.

$ sudo apt install imagemagick

ImageMagickをaptでインストールした後にGemfileに下記を追記

gem 'rmagick'

bundle install でエラー

$ bundle install --path vendor/bundle
...

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

current directory:
/home/user/rails/carrierwave/vendor/bundle/ruby/2.6.0/gems/rmagick-4.0.0/ext/RMagick
/home/user/.rbenv/versions/2.6.4/bin/ruby -I /home/user/.rbenv/versions/2.6.4/lib/ruby/2.6.0 -r
./siteconf20190904-14472-nwlwr9.rb extconf.rb
checking for brew... no
checking for pacman... no
checking for gcc... yes
checking for pkg-config... no


ERROR: Can't install RMagick 4.0.0. Can't find pkg-config in
/home/user/.rbenv/versions/2.6.4/bin:/home/user/.rbenv/libexec:/home/user/.rbenv/plugins/ruby-build/bin:/home/user/.rbenv/shims:/home/user/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games


*** 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=/home/user/.rbenv/versions/2.6.4/bin/$(RUBY_BASE_NAME)

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

/home/user/rails/carrierwave/vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0-static/rmagick-4.0.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in
/home/user/rails/carrierwave/vendor/bundle/ruby/2.6.0/gems/rmagick-4.0.0 for inspection.
Results logged to
/home/user/rails/carrierwave/vendor/bundle/ruby/2.6.0/extensions/x86_64-linux/2.6.0-static/rmagick-4.0.0/gem_make.out

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

In Gemfile:
  rmagick


各ライブラリがインストールされていなかったのが原因
libmagickcore-devをaptでインストールした後にbundle installできた

$ sudo apt install libmagickcore-dev

参考:ruby-on-rails – dockerでgem“ rmagick”をインストールできない - コードログ