Installing RMagick on Mac OS X and Ubuntu

I haven’t done anything with RMagick at all, partly because it relies on ImageMagick which many consider difficult to install on Mac OS X. Lately I’ve had a reason to use the excellent Gruff charting library, so it was time to buckle down and install this stuff.

As it turns out, it’s really not as complicated as some people say. Assuming you’ve already got macports and rubygems installed, it basically comes down to this:

sudo port install freetype
sudo port install ghostscript
sudo port install imagemagick
#sudo port install graphicsmagick
sudo gem install rmagick

Somewhere I got the idea to also install graphicsmagick after imagemagick, but for some reason port doesn’t seem to be able to find the package; It tries a few dozen sites and fails, so I commented it out above, but feel free to try it yourself. But no matter, it seems to not be necessary; I can now create images, render text, write them to disk, etc.

On Ubuntu (6.10), the incantation is different, but even simpler (via EXPRESSICA:

sudo apt-get install imagemagick
sudo apt-get install libmagick9-dev ruby1.8-dev
sudo gem install rmagick

The only caveat is that if you’re running without swap space and have less than a couple hundred megs of free RAM (e.g. on a VPS server) you may need to stop some of your processes before attempting that last line, or you’ll get this not-so-helpful set of errors after it runs for a while, consumes all available RAM, and subsequently crashes:

Building native extensions. This could take a while…
ERROR: While executing gem … (Gem::Installer::ExtensionBuildError)
ERROR: Failed to build gem native extension.

Hopefully this will save someone a few hours.