the other dell

Less precious gems

I’m learning Ruby and Rails. One of my ongoing projects is a remake of threewordpoems.com in Rails 4. I’d left this project alone whilst doing some other work and expected nothing to have affected it. However, when I returned to it, running rails server generated this error:

/Users/simondell/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rmagick-2.13.4/lib/rmagick_internal.rb:11:in require': This installation of RMagick was configured with ImageMagick 6.9.0 but ImageMagick 6.9.1-10 is in use. (RuntimeError) from /Users/simondell/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rmagick-2.13.4/lib/rmagick_internal.rb:11:in <top (required)>’ from /Users/simondell/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rmagick-2.13.4/lib/rmagick.rb:1:in require' from /Users/simondell/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rmagick-2.13.4/lib/rmagick.rb:1:in <top (required)>’ from /Users/simondell/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.9.6/lib/bundler/runtime.rb:76:in require' from /Users/simondell/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/bundler-1.9.6/lib/bundler/runtime.rb:76:in block (2 levels) in require’…

I didn’t recall doing anything which may have affected RMagick directly, however, I had done several things which may indirectly have affected it. I can’t be sure which was the culprit, but it’s likely one of: updating OSX (10.10.4 -> 10.10.5), updating xCode (or its command-line tools), updating homebrew, updating mysql.

Although it was ages ago (> 1 year), I’m pretty sure I installed both imagemagick and rmagick myself, using homebrew and gem respectively. I tried reinstalling imagemagick, requesting the version identified in the error message:

	brew install imagemagick 6.9.0

… but no such version exists for homebrew. So…

	brew search imagemagick

… listed the following results:

imagemagick homebrew/versions/imagemagick-ruby186

On a whim, I brew installed the latter one. This changed the error reported by rails server:

bin/rails:6: warning: already initialized constant APP_PATH (it puts the path here but I don’t want to show you how my User directory is structured) bin/rails:6: warning: previous definition of APP_PATH was here

That’s cryptic and, to a relative Rails n00b, mystifying. Searching Google for the exact search message is often a good strategy, and that lead directly to a discussion on the Rails Github issue tracker. The first suggestion was to reinstall RVM - which I don’t use, so I skipped that. Removing Spring from my project had no effect. Ditto for the pg gem (this isn’t yet part of my project but it will be when I get to follow the relevant part of Rails Tutorial).

The next tip from the discussion thread was to run this command:

	rake rails:update:bin --trace

… which changed the error from rails server to this one:

$ rake rails:update:bin –trace rake aborted! LoadError: dlopen(/Users/simondell/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/rmagick-2.13.4/RMagick2.bundle, 9): Library not loaded: /usr/local/lib/libMagickCore-6.Q16.2.dylib Referenced from: /Users/simondell/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/rmagick-2.13.4/RMagick2.bundle Reason: image not found - /Users/simondell/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/extensions/x86_64-darwin-14/2.1.0-static/rmagick-2.13.4/RMagick2.bundle /Users/simondell/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rmagick-2.13.4/lib/rmagick_internal.rb:11:in require' /Users/simondell/.rbenv/versions/2.1.3/lib/ruby/gems/2.1.0/gems/rmagick-2.13.4/lib/rmagick_internal.rb:11:in <top (required)>’…

At this point, also somewhat whimsically, I tried reinstalling rbenv (wondering if my tools had simply got confused about paths). That changed the error back to the mystical “already initialized constant APP_PATH”. Given the error explicitly mentions “RMagick2.bundle”, I thought I should probably also reinstall the rmagick gem.

	gem uninstall rmagick
	gem install rmagick

This changed the rails server error to something much more useful:

Could not find rmagick-2.13.4 in any of the sources Run bundle install to install missing gems.

Following the recommendation finally fixed my issues. Now I can go back to following tutorials.