The installation of gem rmagick fails

The installation of rmgick fails even if you follow the instructions in the official documentation.
Does anyone know how to solve this problem?

official documentation:


    working_directory: ~/app
      - image: circleci/ruby:2.5.1-node-browsers
      - checkout
      - run: sudo apt-get update && sudo apt-get install python3-pip groff-base
      - run: sudo apt-get install imagemagick libmagickcore-dev libmagickwand-dev
      - restore_cache: &restore_gems_cache
            - production-rails-peep-bundle-{{ checksum "Gemfile.lock" }}
            - production-rails-peep-bundle-
      - run: bundle check --path=vendor/bundle || bundle install --path vendor/bundle --jobs 4 --retry 3

The error log is as follows

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

   current directory: /usr/local/bundle/gems/rmagick-4.1.2/ext/RMagick
/usr/local/bin/ruby -r ./siteconf20201109-18-1o9h6zv.rb extconf.rb
checking for brew... no
checking for pacman... no
checking for Ruby version >= 2.3.0... yes
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
Package 'MagickCore', required by 'virtual:world', not found

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

*** 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:

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


extconf failed, exit code 1

Gem files will remain installed in /usr/local/bundle/gems/rmagick-4.1.2 for
Results logged to

An error occurred while installing rmagick (4.1.2), and Bundler cannot continue.
Make sure that `gem install rmagick -v '4.1.2' --source ''`
succeeds before bundling.

In Gemfile:
The command '/bin/sh -c set -x  && apk update  && apk add --no-cache --virtual build-dependencies      build-base      git      mysql-dev      ca-certificates      openssl  && echo 'gem: --no-rdoc --no-ri' >> /.gemrc  && gem install bundler  && bundle install -j 4  && rm -rf /usr/lib/lib/ruby/gems/*/cache/*  && rm -rf ~/.gem  && apk del build-dependencies  && apk add --no-cache mariadb-client-libs imagemagick' returned a non-zero code: 5

Exited with code exit status 5
CircleCI received exit code 5

Hi @muramura!

Welcome to Discuss and thanks for posting such helpful information!

I did find some posts online of people also running into similar errors when installing (though it seemed like local installs vs. installing in a CI container):

This one too:

There was also a note in the docs you linked to with a similar error and possible workaround of setting the path:


With all the above said I was trying to replicate the error you were seeing on your builds and was unable to in my own test, so if the above doesn’t get it working for you can you either:

  1. Share a link to a failed build here in this post so I can investigate further (only if you are comfortable posting it)
  2. If you don’t want to publicly share the link, submit a support request and note this post in the submission and include a link to a build. I can then grab that ticket and continue the investigation there

Thank you!