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:
- yajl-ruby 1.10 did show up in the output of the bundle command
- Our rails application failed to start due to a cannot load such file – yajl error.
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.
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.
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:
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:
You can manually update the Gemfile.lock to tell it to use the 64 bit version you compiled earlier. Change the line to read
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!