155

When I try do install rmagick I get the following error message:

Can't install RMagick 2.13.1. Can't find MagickWand.h.
*** 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.

I'm on Mac OSX 10.6.8, ruby 1.9.2p290, rvm 1.10.2.

Can anyone help me please to solve this problem.

blawzoo
  • 2,465
  • 4
  • 19
  • 24
  • 1
    maybe this helps: http://www.ruby-forum.com/topic/190824 – Daniel Jan 29 '12 at 02:33
  • Hi Daniel.The link you provided gives a solution for Debian `apt-get -y install libmagick9-dev ` doesn't work for Mac OSx unfortunately.Is there another alternative – blawzoo Jan 29 '12 at 13:24
  • Try this: https://github.com/maddox/magick-installer That worked with apt-get, C_..., brew didn't – jstreebin Feb 24 '13 at 20:57
  • 1
    TL;DR: If you're getting this after Mavericks upgrade, try brew uninstall/reinstall imagemagick/pkgconfig (as suggested below by jwadsack) – thewoolleyman Apr 16 '14 at 03:36
  • See my answer here https://stackoverflow.com/questions/12292896/installing-rmagick-gem-cant-find-magickwand-h/44126407#44126407 – Aleksandar Pavić May 23 '17 at 05:25

32 Answers32

272

If you're on Ubuntu, installing this package is what fixed it for me:

sudo apt-get install libmagickwand-dev
serv-inc
  • 35,772
  • 9
  • 166
  • 188
SporkInventor
  • 3,120
  • 2
  • 16
  • 11
  • 5
    This is the answer. Please accept it instead of the above one. – northtree Feb 07 '13 at 07:00
  • 2
    Urgh, an additional 75.2MB of additional space will be used. Do I really need all 75 new packages? – Jonathon Horsman May 15 '13 at 10:58
  • 4
    @JonathonHorsman Correct me if I am wrong, but this your first time installing anything ImageMagick ? In order for rmagick gem to function you need ImageMagick developer libraries, and all of their associated dependencies. So unfortunately, yes you do need all of those packages. On the plus side, your computer will have world class image processing capabilities! – SporkInventor May 15 '13 at 15:13
  • 10
    @northtree - note that the original poster was asking about OS X, not Ubuntu – Darren Cheng Mar 12 '14 at 18:53
  • 2
    You also need the `imagemagick` package: github.com/rmagick/rmagick/wiki/Installing-on-Ubuntu – Robin Clowers Oct 16 '14 at 00:38
  • Please upvote, took me 1/2 day to find this correct answer (for Ubuntu 14.04) – pferrel Mar 19 '15 at 17:33
143

It looks like ImageMagick 7 changed include file path.

On building rmagick, since it includes file as wand/MagickWand.h There are no workarounds. It looks like sticking with ImageMagick 6 for now.

On Mac OS X (I tested on Sierra), I used HomeBrew's versions tap like:

brew tap homebrew/versions
brew install imagemagick@6

Then, use the path shown on above installation:

PKG_CONFIG_PATH=/usr/local/opt/imagemagick@6/lib/pkgconfig gem install rmagick

To install with ImageMagick 6.

shigeya
  • 4,862
  • 3
  • 32
  • 33
79

I didn't want to mess with environment variables since I wanted bundler to be able to compile this gem on its own on a CI machine. Instead, I used Homebrew to install pkg-config:

brew install pkgconfig

and the next time I tried compiling the RMagick gem it found the header file without issue.

(This is pkg-config 0.28, ImageMagick 6.8.0-10, and RMagick 2.13.2, all on Mountain Lion.)

Fiona Hopkins
  • 1,966
  • 15
  • 14
  • 18
    In my case (after Mavericks upgrade which seems to have dropped all linked formulae): `brew uninstall pkgconfig imagemagick`, `brew install imagemagick pkgconfig`, `bundle`. – jwadsack Mar 10 '14 at 00:50
  • `brew unlink pkgconfig` and then `brew link pkgconfig`. This is after mavericks update. – Anna B Oct 08 '14 at 13:27
71

I had a similar issue with running

$ gem install rmagick

First of all, do you have imagemagick installed? If you're not sure, run

$ convert --version

If you do, you probably either installed it with fink or macports (maybe homebrew?). What is happening is that rvm can't find the imagemagick directory.

After reading https://superuser.com/questions/361435/i-have-compiled-imagemagick-on-my-centos-and-rmagick-wont-install I exported the imagemagick path by adding

$ export PKG_CONFIG_PATH="/opt/local/lib/pkgconfig:$PKG_CONFIG_PATH"

to my ~/.bash_profile, sourcing the new profile, then running:

gem install rmagick

It worked for me after I did this.

seymore_strongboy
  • 934
  • 10
  • 16
Darren Cheng
  • 1,435
  • 14
  • 12
  • Thanks A lot Darren it just work.You right rvm was not seeing the imagemagick path – blawzoo Jan 31 '12 at 14:33
  • 1
    I updated PKG_CONFIG_PATH to /Dir/to/where/found/MagickCore.pc and still end up with "Can't install RMagick 2.13.1. Can't find MagickWand.h" .. any suggestions why it might not be picked up and what else I can try .. Not sure how to use the -l option mentioned in the post you linked? – codeObserver Mar 02 '12 at 19:34
  • 6
    Might want to mention that second step, because your first step alone didn't work for me (though I was using tmux): `ln -s /usr/local/include/ImageMagick/wand /usr/local/include/wand && ln -s /usr/local/include/ImageMagick/magick /usr/local/include/magick` – jackyalcine Jul 13 '12 at 19:48
  • 8
    on my mac, this command should change to ` $ export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"` – linjunhalida May 24 '13 at 06:54
  • may your children be pretty and your wife prettier. saved me hours of troubleshooting. – Mina Jun 20 '13 at 13:51
  • 10
    Worth noting that PKG_CONFIG_PATH relates to the pkg-config utility, which wasn't installed by default on my Mac. I got `/usr/local/bin/Magick-config: line 41: pkg-config: command not found` warnings when I did `gem install rmagick`. I used `brew install pkg-config` to get pkg-config installed, then set the `PKG_CONFIG_PATH` as described here and the gem install worked. – jscott Nov 25 '13 at 18:02
  • None of these tips worked for me :-( argh. I hate RMagick. Need help http://stackoverflow.com/questions/39494672/rmagick-installation-cant-find-magickwand-h – 0x4a6f4672 Oct 18 '16 at 09:54
  • If you're on Homebrew and fish, then it's `set -x PKG_CONFIG_PATH /usr/local/lib/pkgconfig $PKG_CONFIG_PATH`. Yes, there's a space between the last two parameters. – mostlydev May 30 '17 at 09:46
47

fix this setting the include path of your current imagemagick installation:

Install ImageMagick with brew

brew install imagemagick

find library

$ mdfind MagickWand.h
/usr/local/Cellar/imagemagick/6.7.5-7/include/ImageMagick/wand/MagickWand.h

Install rmagick gem

$ C_INCLUDE_PATH=/path/MagickWand.h gem install rmagick

example:

$ C_INCLUDE_PATH=/usr/local/Cellar/imagemagick/6.7.5-7/include/ImageMagick/ gem install rmagick
xonico
  • 939
  • 1
  • 7
  • 6
  • 3
    On my mac I had to get two directories in the the PKG_CONFIG_PATH. I added these two export statements to my .zshrc file (remember to source the file before you try to install imagemagick): export PKG_CONFIG_PATH="/usr/local/Cellar/imagemagick/6.7.7-6/include/ImageMagick/wand:$PKG_CONFIG_PATH" export PKG_CONFIG_PATH="/usr/local/Cellar/imagemagick/6.7.7-6/lib/pkgconfig:$PKG_CONFIG_PATH" – Don Leatham Aug 18 '12 at 22:54
  • I attempted this and it got around the MagickWand.h problem, but then had an issue with Magick-config – Brett Hardin Feb 12 '13 at 16:14
  • working running C_INCLUDE_PATH=/usr/local/Cellar/imagemagick/6.7.5-7/include/ImageMagick/ brew install --fresh -vvvvv php54-imagick – jeremymarc Feb 19 '13 at 19:28
  • This steps worked fine for me except with small modification. In the above steps, the example is given correctly but the step includes the file itself in the include path. We need to give only path as specified in the example. – maniempire Mar 15 '16 at 16:10
  • Installing imagick version 6 did the trick for me. i did following: 1) brew install rmagick 2) brew tap homebrew/versions brew install imagemagick@6 3) C_INCLUDE_PATH=/usr/local/Cellar/imagemagick@6/6.9.8-4/include/ImageMagick-6/ gem install rmagick – rosnk Apr 27 '17 at 13:58
39

I marked this as a favorite because it seems to come back to bite me with every new system I need to install RMagick on (and time has passed and version numbers have rolled).

Mac OS X 10.8.4

rvm 1.22.3

ruby-2.0.0-p247

Xcode 4.6.3 developer tools installed

$ brew install imagemagick
==> /usr/local/Cellar/imagemagick/6.8.6-3

$ brew install pkgconfig
==> /usr/local/Cellar/pkg-config/0.28

$ C_INCLUDE_PATH=/usr/local/Cellar/imagemagick/6.8.6-3/include/ImageMagick-6 PKG_CONFIG_PATH=/usr/local/Cellar/imagemagick/6.8.6-3/lib/pkgconfig/ gem install rmagick
Successfully installed rmagick-2.13.2

Many thanks to everyone who added helpful answers above!

tobinjim
  • 1,862
  • 2
  • 19
  • 31
29

Mac users using brew

If you can use v6 of ImageMagick instead of 7, you can try this

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

Note this will unlink your existing IM installation, so be careful if you have other projects on your machine using ImageMagick without problems.

Adam Grant
  • 12,477
  • 10
  • 58
  • 65
12

For my own and others edification, I got past the error about the magicwand.h by using the suggestion xonico. MDFind plus the C_INCLUDE_PATH. However, it then gave me an error about MagickCore.pc. My final command to get this working had to include both like so:

 C_INCLUDE_PATH=/usr/local/Cellar/imagemagick/6.7.7-6/include/ImageMagick/ PKG_CONFIG_PATH=/usr/local/Cellar/imagemagick/6.7.7-6/lib/pkgconfig/ gem install rmagick

Obviously your paths will vary depending on whether you're using brew like me and what version of imagemagick you were installing. Also, xcode command line tools did have to be installed, as others have mentioned.

Thanks for everyone's posts on this! I am plussing your answers since it contributed to mine!

fregas
  • 3,192
  • 3
  • 25
  • 41
11

For Ubuntu:

sudo apt-get install imagemagick libmagickwand-dev
gem install rmagick
rusllonrails
  • 5,586
  • 3
  • 34
  • 27
  • While this may be informative to linux users facing the same issue the OP has explicitly specified that (s)he is using Mac OS and thus this answer can be misleading. At the very least please mention that answer is meant for linux (which distributions?) . – lorefnon Jul 07 '14 at 07:32
8

I had a problem after update to Maverics. It have lost a lot of linkings. In my case I had to refresh links to pkg-config

brew unlink pkg-config
brew link pkg-config

Then installing rmagick worked like a charm.

user81620
  • 81
  • 1
  • 1
7

I updated to Mountain Lion and started getting this same problem. I had to re-install brew, XCode, the XCode tools - pretty much the whole environment!

I eventually solved this problem using the answer from phopkins above...

brew install pkgconfig

Once that was successfully completed (I had to delete some old symlinks first) then I was able to successfully install the RMagick gem

Tim Bull
  • 2,375
  • 21
  • 25
7

For Ubuntu users: It will never done directly on Ubuntu. You should first install packages to run this command...:

sudo apt-get install libmagickwand-dev  

...and then do install:

gem install rmagick

You may get the same issue, for that, Try clearing your apt repository and removing any broken packages first:

sudo apt-get update
sudo apt-get autoclean
sudo apt-get clean
sudo apt-get autoremove

If the system identifies any broken packages, forcefully remove them (replace package_name with your own):

sudo dpkg --remove -force --force-remove-reinstreq package_name

Then re-install any missing packages again. :)

mat
  • 1,367
  • 1
  • 13
  • 18
Awais
  • 1,803
  • 22
  • 26
7

This worked for me on Mac OsX

Install Imagemagick:

brew remove imagemagick
brew install imagemagick

Make sure pkg-config is correctly linked:

brew uninstall pkg-config
brew install pkg-config
brew unlink pkg-config && brew link pkg-config

Install gem

gem install rmagick
Brian
  • 123
  • 1
  • 4
7

An issue for me was that rmagick is out of date and not updated regularly. If you have too new of an ImageMagick version, then it might not be compatible. Check your version of ImageMagick using the following:

$ convert --version

If the ImageMagick version is > 7, it is not compatable with rmagick. The user will get errors such as

Can't install RMagick 2.16.0. Can't find MagickWand.h.
*** extconf.rb failed *** 

Go back to version six of ImageMagick until they update rmagick to be compatible with version seven of ImageMagick. Someone has hosted the appropriate version(6) in a separate gem - 'imagemagick@6'.

If you need rmagick to work but currently have an imagemagick version 7 or higher, here are the steps to switch:

$ gem install imagemagick@6
$ brew unlink imagemagick
$ brew link imagemagick@6 --force
farrellw
  • 1,340
  • 15
  • 12
6

Helped me on Debian Wheezy 64bit

 apt-get install libmagickcore-dev libmagickwand-dev
mat
  • 1,367
  • 1
  • 13
  • 18
4

Try reinstalling both Imagemagick and PkgConfig. That should fix it for Mavericks

  • brew update && brew upgrade
  • brew reinstall imagemagick
  • brew reinstall pkgconfig
Jones Agyemang
  • 1,230
  • 16
  • 15
2
C_INCLUDE_PATH=/usr/local/Cellar/imagemagick/6.7.7-6/include/ImageMagick gem install rmagick
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
2

I was really struggling with this on OS X Mountain Lion (after upgrading from Lion) and none of the suggestions regarding C_INCLUDE_PATH, PKG_CONFIG_PATH, ln'ing various files, etc., were working. On the same day I upgraded to Mountain Lion, I also upgraded XCode to 4.5.2, but I didn't really think too much of this.

Eventually I stopped trying to install RMagick and had to pass on the work to a colleague.

Then, by chance, I found that I was trying to use bundle install on another project and I wasn't able to install the json gem because "make" could not be found. I checked into that and found you need to go to XCode -> Preferences -> Downloads and install the command line tools to get make working again. The json gem installed fine.

Then I paused...and tried

gem install rmagick

One more time. It worked perfectly.

adriandz
  • 999
  • 1
  • 10
  • 21
2

for a rails based application, I found this

sudo apt-get install -y libmagickwand-6-headers
C_INCLUDE_PATH=/usr/include/ImageMagick-6 gem install rmagick
bundle update rmagick
bundle install

worked on debian jessie

Dorian
  • 22,759
  • 8
  • 120
  • 116
waghanza
  • 163
  • 1
  • 9
1

In linux OS:

C_INCLUDE_PATH=/usr/local/include/ImageMagick-6/ gem install rmagick

Building native extensions. This could take a while...

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

        /home/vagrant/.rvm/rubies/ruby-1.9.3-p0/bin/ruby extconf.rb
...
Package MagickCore was not found in the pkg-config search path.
Perhaps you should add the directory containing `MagickCore.pc'

then:

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig"

in my .bashrc file to pick up MagickCore.pc, then created two symlinks:

ln -s /usr/local/include/ImageMagick/wand /usr/local/include/ImageMagick-6/wand
ln -s /usr/local/include/ImageMagick/magick /usr/local/include/ImageMagick-6/magick

Now:

$ gem install rmagick
Building native extensions.  This could take a while...
Successfully installed rmagick-2.13.2
1 gem installed

boom everything works fine.

tokhi
  • 21,044
  • 23
  • 95
  • 105
1

I ran into this because I'd run OS X's Migration Assistant and nothing was relinked after the migration. You need to check the output of Wand-config --ldflags --libs. In my case it gave:

$ Wand-config --ldflags --libs
/usr/local/bin/Wand-config: line 50: pkg-config: command not found
/usr/local/bin/Wand-config: line 53: pkg-config: command not found

After relinking pkg-config, libpng, and libfreetype, that became:

$ Wand-config --ldflags --libs
-L/usr/local/Cellar/imagemagick/6.8.8-9/lib -lMagickWand-6.Q16 -lMagickCore-6.Q16 
-L/usr/local/Cellar/imagemagick/6.8.8-9/lib -lMagickWand-6.Q16 -lMagickCore-6.Q16 

And then:

$ gem install rmagick
Building native extensions.  This could take a while...
Successfully installed rmagick-2.13.2
Parsing documentation for rmagick-2.13.2
Done installing documentation for rmagick after 4 seconds
1 gem installed
Bob Aman
  • 32,839
  • 9
  • 71
  • 95
1

At arch linux, after installing imagemagick@6, gem wasn't able to install package rmagick and got error below.

Can't install RMagick 2.16.0. Can't find MagickWand.h

Worked for me using below steps

  1. added pkgconfig path to .bashrc

    export PKG_CONFIG_PATH="/usr/lib/imagemagick6/pkgconfig"

  2. Created two symlinks as below

    ln -s /usr/include/ImageMagick-6/wand /usr/include/ImageMagick-6/wand

    ln -s /usr/local/include/ImageMagick/magick /usr/include/ImageMagick-6/magick

  • 2
    Arch usually doesn't keep around older versions like this (I wasn't clear on what was meant by imagemagick@6 above), but this was really easy on my arch box -- there is a package called `imagemagick6` available in `extra`; simply install that and it'll remove `imagemagick` (i.e. v7 will be downgraded to v6 in place) – jaustin May 29 '18 at 20:39
  • @jaustin yesterday , I already mentioned here "gem wasn't able to install package" – Mizanur Rahman Mojumder May 31 '18 at 14:32
  • 1
    I wasn't talking about gem installation (directly); my comment concerned arch package downgrade to imagemagick 6. i.e. there's no need for all that PKG_CONFIG.... stuff, simply `pacman -S imagemagick6` (assuming you're fine with downgrading). – jaustin Jun 01 '18 at 16:19
1

There are some variants to this problem. Mostly the case is dealing with a legacy application that run older versions of ruby.

rmagick has a dependancy on imagemagick... but not just any. If you've gone too far ahead, it may be wise to backtrack:

brew uninstall imagemagick

Then proceed with an appropriate version

brew install imagemagick@6

then you path needs to be adjusted and forced upon homebrew

export PATH="/usr/local/opt/imagemagick@6/bin:$PATH"
brew link --force imagemagick@6

then you can install rmagick to most recent or versioned

gem install rmagick -v '2.15.4' --source 'https://rubygems.org/'
Jerome
  • 5,583
  • 3
  • 33
  • 76
0

I had a hard time getting this same issue to work when I had a default ImageMagick install on OSX 10.8 (no homebrew or macports). No combination of the suggestions in this thread or threads linked to from this thread worked for me (modifying the paths for my local install of course).

I simply deleted the default ImageMagick 6 install, and then reinstalled with macports. My rmagick install worked immediately after with no other changes.

0

on OSX Maverick 10.9.1 it took me ages to figure it out but I solved these issues the following way:

nano /etc/paths

changed:

/usr/bin
/bin
/usr/sbin
/sbin
/usr/local/bin

into:

/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

that that local stuff, like 'brew' is loaded first.

now I hit 'brew doctor' into the terminal, to see if there's something messed up

if you get the following output Your system is ready to brew. everthing is fine. if not ti will tell you what to do. Like kick out unbrewed stuff, broken libs, clean symlinks and whatnot.

When you are ready to brew, you need ghostscript(for pdfs), libpng, imagemagick via brew.

then you can happily type : 'gem install rmagick', in case you did't kill your ruby setup. But thats easy to reinstall via your cleaned up brew.

PS: another helpful command is: 'which convert', to show you what version of imagemagick is used by the system.

as well as --version

so if you installed git via brew and do 'git --version' and it returns some apple git version, your load path is broken...

RedRoosterMobile
  • 786
  • 10
  • 21
0

On Mac OS X 10.9, try to update your Xcode if there's a warning about it.
$ brew doctor
I you found some warning, do:
$ sudo /Developer/Library/uninstall-developer-folder

Then try:
$ bundle install
again

That worked fine for me.

Fabricio
  • 1,168
  • 8
  • 9
0

On CentOS 6.5 x64, it was pretty easy:

yum install ImageMagick ImageMagick-devel

gem install rmagick -v '2.13.2'
Fernando Vieira
  • 3,177
  • 29
  • 26
0

I was able to fix this by upgrading to 2.13.2

scootklein
  • 708
  • 1
  • 8
  • 21
0

All brew options failed to install rmagick 2.13.1 on yosemite 10.10

this worked
get the latest RVM

\curl -sSL https://get.rvm.io | bash -s stable --ruby rvm install 2.1.1 rvm use 2.1.1

download and install the package file http://cactuslab.com/imagemagick

(I used pacifist to install)

Confirm location of MagickCore.pc file

mdfind magickcore.pc

eg. /opt/ImageMagick/lib/pkgconfig/MagickCore.pc

Manually download rmagick-2.15.2.gem file https://rubygems.org/gems/rmagick/versions/2.15.2

from that dir

sudo C_INCLUDE_PATH=/opt/ImageMagick/include/ImageMagick-6/ PKG_CONFIG_PATH=/opt/ImageMagick/lib/pkgconfig gem install --local rmagick-2.15.2.gem

If you are having issues with bundle installer still complaining about 2.13.1

In your gem file / gem.lock file upgrade ALL dependencies

rmagick (2.13.1) - > rmagick (>= 2.15.2)

Community
  • 1
  • 1
johndpope
  • 5,035
  • 2
  • 41
  • 43
0

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.

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.


You may also need to set the following symbolic links here before it can work:

ln -s /usr/local/lib/libMagickWand-6.Q16.so.6 /home/marcelo/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/extensions/x86_64-linux/2.2.0-static/rmagick-2.16.0/libMagickWand-6.Q16.so.6
sudo ln -s /usr/local/lib/libMagickWand-6.Q16.so.6 /usr/lib
ln -s /usr/local/lib/libMagickCore-6.Q16.so.6 /home/marcelo/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/extensions/x86_64-linux/2.2.0-static/rmagick-2.16.0/libMagickCore-6.Q16.so.6
sudo ln -s /usr/local/lib/libMagickCore-6.Q16.so.6 /usr/lib
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
0

Got same error for alpine 3.9 image build. It comes with ImageMagick 7.0.8.38-r0

To fix that you either use alpine 3.5 with ImageMagick 6.9.6.8-r1:

FROM alpine:3.5

Or install ImageMagick 6.9.6.8-r1 with package repository for 3.5:

RUN apk add imagemagick-dev=6.9.6.8-r1 --repository http://dl-3.alpinelinux.org/alpine/v3.5/main/

There is an open issue in rmagick repo regarding failed builds for ImageMagick 7.0.x. so hopefully it will be fixed soon.

Martin
  • 4,042
  • 2
  • 19
  • 29
0

I just faced this issue on Ubuntu 20.04, what fixed the it for me was install imagemagick through linuxbrew:

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

Then just follow brew documentation:

To have imagemagick@6 first in your PATH run:

 echo 'export PATH="/home/linuxbrew/.linuxbrew/opt/imagemagick@6/bin:$PATH"' >> /home/visiond/.bash_profile

For compilers to find imagemagick@6 run:

  export LDFLAGS="-L/home/linuxbrew/.linuxbrew/opt/imagemagick@6/lib"
  export CPPFLAGS="-I/home/linuxbrew/.linuxbrew/opt/imagemagick@6/include"

For pkg-config to find imagemagick@6 run:

  export PKG_CONFIG_PATH="/home/linuxbrew/.linuxbrew/opt/imagemagick@6/lib/pkgconfig"

Then try to install rmagick again

gem install rmagick -v '2.16.0'

if it complains about missing pkg-config run

brew reinstall pkg-config

Now try installing rmagick again, everything should work.

If you're using WSL, it could still fail, changing

gem 'rmagick', '~> 2.16.0'

to

gem 'rmagick', '~> 2.15', '>= 2.15.4', :platforms => :ruby

Should fix the issue completely.

Update

Sometimes the brew option will give you a weird error that says something like

Rmagick was configured with <some-imagemagick-version> but <other-imagemagick-version> is in use

This is normally an issue related to linuxbrew, what I did to fix it was

rollback everything explained up there ^^

  brew uninstall imagemagick@6
  brew uninstall pkg-config

then remove all these lines from your bashrc

 export PATH="/home/linuxbrew/.linuxbrew/opt/imagemagick@6/bin:$PATH"
 export LDFLAGS="-L/home/linuxbrew/.linuxbrew/opt/imagemagick@6/lib"
 export CPPFLAGS="-I/home/linuxbrew/.linuxbrew/opt/imagemagick@6/include"
 export PKG_CONFIG_PATH="/home/linuxbrew/.linuxbrew/opt/imagemagick@6/lib/pkgconfig"

Refresh your terminal with latest changes

source ~/.bashrc

Make sure you don't have any imagemagick installed by running:

convert -version

If you get something like

Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff webp wmf x xml zlib

it means you still have imagemagick in your system, this could be due to various reasons:

  • You installed imagemagick from source
  • You installed imagemagick through apt

If 1

Remove imagemagick by going to the folder where you ran make install and just run make uninstall, this should remove the package completely, then try convert -version again

If 2

Check the version of the package, if you're trying to install rmagick < v3, then you'll need imagemagick 6, if not, any imagimagick works.

Assuming you have a new version of imagemagick (IE: 7) and you need an older version for your rmagick, just do a

sudo apt remove --purge imagemagick

Now that we have our system clean, we can install imagemagick again

sudo apt-get install imagemagick-6.q16

try installing rmagick again

gem install rmagick -v '2.16.0

if it complains about MagickCore, it means you need to install libmagickwand-dev, to do so:

sudo apt-get install libmagickwand-dev

now try again, everything should work :)