Rails: Error installing rmagick - ERROR: Failed to build gem native extension

Ruby on-Rails

Ruby on-Rails Problem Overview


I am trying to run one project on my local machine. I installed Ruby and Rails on my Mac OS system. It is working properly. I can create a new project and can run it properly without any error, but when I try to run the existing project it says that we have to bundle install. When I run that command I get the following error:

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

When I run gem install rmagick -v '2.13.2' it gives me the following error:

ERROR:  Error installing rmagick:
ERROR: Failed to build gem native extension.

/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb
checking for Ruby version >= 1.8.5... yes
checking for gcc-4.2... yes
checking for Magick-config... no
Can't install RMagick 2.13.2. Can't find Magick-config in /usr/local/rvm/gems/ruby-1.9.3-p392/bin:/usr/local/rvm/gems/ruby-1.9.3-p392@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p392/bin:/usr/local/rvm/gems/ruby-1.9.3-p392/bin:/usr/local/rvm/gems/ruby-1.9.3-p392@global/bin:/usr/local/rvm/rubies/ruby-1.9.3-p392/bin:/usr/local/rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/sm/bin:/opt/sm/pkg/active/bin:/opt/sm/pkg/active/sbin

*** 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=/usr/local/rvm/rubies/ruby-1.9.3-p392/bin/ruby


Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rmagick-2.13.2 for inspection.
Results logged to /usr/local/rvm/gems/ruby-1.9.3-p392/gems/rmagick-2.13.2/ext/RMagick/gem_make.out

I have searched and did not find an answer anywhere.

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

For Ubuntu, I used the ff. based on this link:

$ sudo apt-get install libmagick++-dev

Solution 2 - Ruby on-Rails

On a mac (the below code works on OSX Mavericks):

brew install imagemagick
gem install rmagick

Solution 3 - Ruby on-Rails

On Mac you can try this:

$ brew unlink imagemagick
$ brew install imagemagick@6 && brew link imagemagick@6 --force
$ gem install rmagick 

Solution 4 - Ruby on-Rails

I have solved this problem by installing imagemagic:

sudo apt-get install imagemagick

and then install libmagick package:

sudo apt-get install libmagick++-dev

Solution 5 - Ruby on-Rails

For Linux Fedora, I got same error and fixed with below two commands:

yum install ImageMagick

gem install rmagick 

For Centos install ImageMagick-devel package. using below commands:

yum install ImageMagick-devel

gem install rmagick

Solution 6 - Ruby on-Rails

First, make sure you've installed Imagemagick :

$ sudo apt-get install imagemagick

Now, it can build the gem native extension.

Then, install the Rmagick gem :

$ sudo gem install rmagick

Solution 7 - Ruby on-Rails

here's what i did on 16.04,

sudo apt-get install libmagickwand-dev
sudo apt-get install graphicsmagick-imagemagick-compat

and then install gem like that

PATH="/usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/bin-Q16:$PATH" gem install rmagick -v '2.13.2'

Solution 8 - Ruby on-Rails

May be you are installing ImageMagick version 7.x.x which will generate different folder names in your usr/lib/local/include/ImageMagick7.x.x folder. E.g.

In ImageMagick6.x.x version we have magick, wand named folders, where in ImageMagick7.x.x version have named this MagickCore , MagickWand . So this updation is causing the problem in some gem installation like here. Which is using magick/some_header.h or wand/some_header.h (Means they are not updated with the new 7.x.x ImageMagick version).That's why we are getting this error :


    checking for outdated ImageMagick version (<= 6.4.9)... no
    checking for presence of MagickWand API (ImageMagick version >= 6.9.0)... no
     .... 
    checking for wand/MagickWand.h... no

and in log file something like this :

error: 'MagickCore/method-attribute.h' file not found
#include "MagickCore/method-attribute.h"
         ^

Solution

Install the ImageMagick6.x.x version in your system from the official site : https://www.imagemagick.org/download/ and install it using this commands(after extract zip/tar) :

./configure
make 
make install

Then do

gem install rmagick

It will work.

Solution 9 - Ruby on-Rails

As per the error log it looks like "Magick-config" is missing. You need to install ImageMagik or GraphicsMagick. These are the commands you should follow which is taken from RMagik Documentation:

1) Go to http://www.imagemagick.org or http://www.graphicsmagick.org and download the latest version of the software to a temporary directory. the extract them :

- tar xvzf ImageMagick.tar.gz
- cd ImageMagick-x.x.x

- ./configure --disable-static --with-modules --without-perl --without-magick-plus-plus --with-quantum-depth=8

- make
- sudo make install

- sudo gem install rmagick

Solution 10 - Ruby on-Rails

Solution for Ubuntu:

sudo apt-get install imagemagick

ln -s /usr/lib/x86_64-linux-gnu/ImageMagick-6.8.9/bin-Q16/Magick-config /usr/bin/Magick-config

Solution 11 - Ruby on-Rails

first run this: sudo apt-get install imagemagick

then: sudo apt-get install libmagick++-dev

now install rmagick: gem install rmagick

Solution 12 - Ruby on-Rails

Just run these command

$ sudo apt-get install imagemagick
• $ sudo apt-get install libmagick++-dev
• $ sudo gem install rmagick
• $ bundle install

Solution 13 - Ruby on-Rails

Just install ImageMagick-devel package and everything should be fine :)

Solution 14 - Ruby on-Rails

For Ubuntu Server, I installed it by doing this:

sudo apt-get install imagemagick

sudo apt-get install libmagick++-dev

sudo gem install rmagick -v '2.15.4'

Solution 15 - Ruby on-Rails

All here wrong for me :(

this helped:

sudo apt-get install libmagickwand-dev

according to rmagick github page

then bundle install went with no errors

Solution 16 - Ruby on-Rails

I had this same issue when setting up a Rails 6 application in Ubuntu 20.04.

Here's how I solved it

RMagick is an interface between the Ruby programming language and the ImageMagick image processing library. So we first need to install development libraries for ImageMagick:

Step 1:

On Ubuntu, you can run:

sudo apt-get install libmagickwand-dev

On Centos, you can run:

sudo yum install gcc ImageMagick-devel make which

On Arch Linux, you can run:

pacman -Syy pkg-config imagemagick

On Alpine Linux, you can run:

apk add pkgconfig imagemagick imagemagick-dev imagemagick-libs

or you can run if you would like to use ImageMagick 6:

apk add pkgconfig imagemagick6 imagemagick6-dev imagemagick6-libs

On macOS, you can run:

brew install pkg-config imagemagick

or you can run if you would like to use ImageMagick 6:

brew install pkg-config imagemagick@6

On Windows:

  1. Install the latest Ruby+Devkit package which you can get from RubyInstaller for Windows.
  2. You might need to configure PATH environment variable to where the compiler is located. (Ex: set PATH=C:\Ruby27-x64\msys64\usr\bin;C:\Ruby27-x64\msys64\mingw64\bin;%PATH%)
  3. Download ImageMagick-7.XXXX-Q16-x64-dll.exe (not, ImageMagick-7.XXXX-Q16-x64-static.exe) binary from Windows Binary Release, or you can download ImageMagick 6 from Windows Binary Release.
  4. Install ImageMagick. You need to turn on checkboxes Add application directory to your system path and Install development headers and librarries for C and C++ in an installer for RMagick. https://user-images.githubusercontent.com/199156/77183472-b72cbd00-6b11-11ea-8b9a-247bc1f9d8b1.png" />

Step 2:

Install the RMagick ruby gem:

gem install rmagick

Step 3:

Now you can add the RMagick ruby gem to your Gemfile:

gem 'rmagick', '~> 4.1'

Note: As of this writing the latest version is 4.1

Step 4:

Finally, you can run bundle install to install the gem to your application.

Resources: rmagick/rmagick GitHub page

That's all.

I hope this helps

Solution 17 - Ruby on-Rails

If you are using openSUSE, then first check if the ImageMagick installed or not. If it is installed, then do install it development header file.

[arup@sztukajedzenia]$ sudo zypper se imagemagic
root\'s password:

Loading repository data...
Reading installed packages...

S | Name              | Summary                                               | Type
--+-------------------+-------------------------------------------------------+-----------
i | ImageMagick       | Viewer and Converter for Images                       | package
  | ImageMagick       | Viewer and Converter for Images                       | srcpackage
  | ImageMagick-devel | Include Files and Libraries Mandatory for Development | package
  | ImageMagick-doc   | Document Files for ImageMagick Library                | package
  | ImageMagick-extra | Viewer and Converter for Images - extra codecs        | package
[arup@sztukajedzenia]$ sudo zypper in ImageMagick-devel
root\'s password:
Loading repository data...
Reading installed packages...
Resolving package dependencies...

The following 2 NEW packages are going to be installed:
  ImageMagick-devel libbz2-devel
  ........

Solution 18 - Ruby on-Rails

You need to run both the command for ubuntu

sudo apt-get install libmagick++-dev
sudo apt-get install imagemagick

Then try to install

gem install rmagick

Solution 19 - Ruby on-Rails

For mac users, install imagemagick 6 since the newest version 7 isn't compatible.

brew install imagemagick@6
gem install rmagick

The above should work after you uninstall what you already have.

Solution 20 - Ruby on-Rails

For Fedora 27 I resolved this problem:

sudo dnf install ImageMagick-devel ImageMagick
gem install rmagick

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2863141View Question on Stackoverflow
Solution 1 - Ruby on-RailsJonathanView Answer on Stackoverflow
Solution 2 - Ruby on-RailsNeil BillinghamView Answer on Stackoverflow
Solution 3 - Ruby on-RailstevanrajView Answer on Stackoverflow
Solution 4 - Ruby on-RailsMd Sirajus SalayhinView Answer on Stackoverflow
Solution 5 - Ruby on-RailsSumit MunotView Answer on Stackoverflow
Solution 6 - Ruby on-RailsZakariaView Answer on Stackoverflow
Solution 7 - Ruby on-RailsJames MView Answer on Stackoverflow
Solution 8 - Ruby on-RailsShekhar Prasad RajakView Answer on Stackoverflow
Solution 9 - Ruby on-RailsAnand SoniView Answer on Stackoverflow
Solution 10 - Ruby on-RailsSergey FadeevView Answer on Stackoverflow
Solution 11 - Ruby on-RailsAbdul WahedView Answer on Stackoverflow
Solution 12 - Ruby on-RailsKrishna kushwahaView Answer on Stackoverflow
Solution 13 - Ruby on-RailsTommyknockerView Answer on Stackoverflow
Solution 14 - Ruby on-Railsuser7209738View Answer on Stackoverflow
Solution 15 - Ruby on-RailsKovoView Answer on Stackoverflow
Solution 16 - Ruby on-RailsPromise PrestonView Answer on Stackoverflow
Solution 17 - Ruby on-RailsArup RakshitView Answer on Stackoverflow
Solution 18 - Ruby on-RailsSandip MondalView Answer on Stackoverflow
Solution 19 - Ruby on-RailsTristan TaoView Answer on Stackoverflow
Solution 20 - Ruby on-Railsvk26View Answer on Stackoverflow