Services Spotlight:

Fixing 'cannot load such file -- yajl' Windows 7 64bit, Rails, Ruby 2+

Written By Corlew Solutions
Updated February 1, 2014
Published January 18, 2014
Why Corlew Solutions?

We write great software and provide amazing technical support. Contact us today if you need help with a software project:

Article Technology Info

This article discusses the following technologies:

  • Bundler - Tool for managing dependencies in a ruby application.
    (website)
  • yajl-ruby - Ruby gem binding for the YAJL JSON parser.
    (website)

YAJL is a small event-driven JSON parser written in ANSI C. It’s functionality is available to Ruby applications thanks to the yajl-ruby gem. Recently, we ran into an issue installing the pygments.rb 0.5.4 gem on Windows 7 64bit which depends onyajl-ruby 1.1.0. After running bundle install we noticed two issues:

  1. yajl-ruby 1.10 did show up in the output of the bundle command
  2. Our rails application failed to start due to a cannot load such file – yajl error.

The Issue

There is a good thread on the yajl-ruby Issues GitHub page which covers a bit of the history of the bug. It turns out Ruby 2.0.0 introduced changes which caused gems compiled under Ruby 1.9.3 to break. More information about those changes can be found in this announcement from the RubyInstaller team on Google Groups.

The Solution

Fortunately, the workaround is straightforward. The real problem for Windows 7 64bit users is before version 1.4, bundler does not understand how to install 64 bit gems on Windows 7 64bit.

Best Solution - Update Bundler

The best solution is to check your version of bundler gem list bundler and upgrade to at least 1.4. We can confirm it works as of bundler 1.5.2. Once you have upgraded bundler, running bundle should successfully install yajl-ruby on Windows 7 64bit.

Alternate Solution - Manually Edit Gemfile.lock

If you can’t upgrade your version of bundler, or you prefer a manual approach, give this a try. First manually install the gem and make sure it compiles.

1
gem install yajl-ruby -v="1.1.0" --platform=ruby  # Remove `-v="1.1.0" if you want to install the latest version

You should see something similar to the following output:

1
2
3
4
Temporarily enhancing PATH to include DevKit...
Building native extensions.  This could take a while...
Successfully installed yajl-ruby-1.1.0
1 gem installed

Next try running bundle:

1
2
rm Gemfile.lock
bundle

If you see yajl-ruby in the list of gems that bundler outputs then you’re good to go. If you DO NOT see yajl-ruby, then you probably still have an issue with bundler trying to use the 32bit. To fix this, open your Gemfile.lock file in an editor and find the yajl-ruby line. it probably looks something like the following:

1
yajl-ruby (1.1.0-x86-mingw32)

You can manually update the Gemfile.lock to tell it to use the 64 bit version you compiled earlier. Change the line to read

1
yajl-ruby (1.1.0-x64-mingw32)

It’s not ideal, because you’ll have to change this every time you recreate your Gemfile.lock, but it might help you if you can’t update your version of bundler.

We hope you found this article useful. If you see any mistakes, missing features or ways to improve it, please let us know in the comments below so we can update its contents. If you're willing to link to us, we would sincerely appreciate it!

References

  • Google Groups - Announcement from the RubyInstaller team regarding Ruby 2.0.0
  • yajl-ruby Issue #116 - Thread discussing this error on the yajl-ruby GitHub page
  • Bundler Issue #2658 - Thread mentioning versions of Bundler prior to 1.4 have issues installing 64bit gems on Window 7 64bit.

Corlew Solutions is a Web Design and Web Application Development company based in Fairfax Virginia, minutes away Washington D.C. If you're looking for great web design from the Northern Virginia area or web design from the Washington D.C. area we can help. Contact Us today!

comments powered by Disqus