ERROR: Error installing rmagick: in Windows with Ruby 2.2

I cloned my code from git to my Windows machine and when I run bundle install, I am getting this error:

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

D:\project\MyProject2>gem install rmagick -v '2.13.4'

Temporarily enhancing PATH to include DevKit... Building native extensions. This could take a while... ERROR: Error installing rmagick: ERROR: Failed to build gem native extension.

D:/RailsInstaller/Ruby2.2.0/bin/ruby.exe -r ./siteconf20160721-7208-bn9t3e.rb extconf.rb checking for Ruby version

= 1.8.5... yes Invalid drive specification. Unable to get ImageMagick version * 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 tried downloading ImageMagick, and set environment paths as:

CPATH=D:\ImageMagick-6.9.5-Q8\include
LIBRARY_PATH=D:\ImageMagick-6.9.5-Q8\lib

and run bundle install but no use and also tried running

gem install rmagick  -v '2.13.4' --platform=ruby -- --with-opt-lib=D:\ImageMagick-6.9.5-Q8\lib --with-opt-include=D:\ImageMagick-6.9.5-Q8\include

it is showing:

Unable to get ImageMagick version * 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.

Please help.


I had this same issue myself until I finally stumbled upon the answer on Stackoverflow here and here.

Basically you need to follow these steps:

  • Install DevKit. Since I used RailsInstaller to install Ruby on Rails on my laptop, it was already included in the default directory ‘C:\Serever\RailsInstaller\DevKit‘. Otherwise, find the .exe at the RubyInstallers downloads.
  • Install ImageMagick-6.9.5-9-Q16-x86-dll.exe from imagemagick.org. It seems that rmagik2.16 only supports ImageMagick 6, not ImageMagick 7.
  • Make sure that you install the correct version of ImageMagick x86 or x32. If you are unsure what ruby version you have install try this command: ruby -e "puts 1.size". It print 4 if x86 and 8 if x64. answer from here
  • Check the following options on the install screen (more info on the redmine website) :
    • [v] Add application directory to your system path
    • [v] Install development headers and libraries for C and C++
  • Setup in windows environment variables the PATH variable to include the path to ImageMagick. In my case: C:\Server\ImageMagick\. Make sure it is the first variable in the variables list, or you may encounter an “Invalid drive specification” error when extconf.rb tries to identify the ImageMagick version.
  • cd C:\YourRubyProject. Example: C:\Server\htdocs\dev-ruby\redmine.
  • Set CPATH and LIBRARY_PATH environment variables to point respectively to ImageMagick installation directory include and lib subdirectories (so the DevKit will find them at build time)
  • Open C:\Serever\RailsInstaller\DevKit\msys.bat. More details here
  • Run gem install rmagick --platform=ruby -- --with-opt-lib=C:/Server/ImageMagick/lib --with-opt-include=C:/Server/ImageMagick/include. Adjust paths as necessary for your project.
  • Finally, run bundle install, or if necessary bundle update

Note: for those that are looking to install redmine in xampp follow this tutorial. If you get stuck on installing the rmagick lib, return here to this answer and follow the provided steps.