Ruby 2.2 on Windows
This article will discuss workarounds for getting Ruby 2.2 and Rails working on Windows.
Published on:October 14, 2015
Introduction
When Ruby 2.2 was first released, it had serious teething problems on Windows. Many gems did not work (and still don't work) and left users high and dry. Most Ruby devs use OS-X and Linux, so Windows simply isn't a priority for them. Luckily things have gotten better, and it is now possible to use Ruby 2.2 on Windows. This article has a few tips to help you get rolling with Ruby 2.2 on Windows. All tips were tested on Windows 10, but should work equally well on Windows 7 up. Let's get started.
Installing Ruby 2.2
First, we need to install Ruby 2.2. To do this, go to the Ruby Installer downloads page
and grab the latest version of 2.2, which is 2.2.3 as of this writing. Make sure to download the 32-bit version, 64 bit Ruby on Windows still isn't ready for action. I recommend grabbing the zip and extracting it to C:\Ruby22. Make sure that the bin/include/lib/share folders are inside C:\Ruby22 and not a subfolder. Next, you'll need to add Ruby to your path. To do this, hold down the Windows key on your keyboard and press R, then type sysdm.cpl
in the box that pops up and click OK.
This will open up the system properties dialog. Click the Advanced tab, then environment variables down at the bottom.
Under system variables, find Path
and press edit. Click in the variable value text box, push the end key on your keyboard to scroll all the way to end, then type C:\Ruby22\bin
.
Finally, click OK, OK again, and then OK one more time. Now you should be able to run Ruby from a command prompt. To test this, open up a command prompt (shortcut: push the windows key, type cmd
and press enter). and type ruby --version
. If all is well, you'll see the version of Ruby printed. If not, go back and make sure the path to Ruby listed in the environment variables is correct. Also try rebooting.
Now that Ruby is installed and working, go grab the devkit off the Ruby Installer downloads page. The file you want is listed under "For use with Ruby 2.0 and above (32bits version only):". The filename as of this writing is DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe
. Open the installer and extract it to C:\Ruby22
Once completed, open a command prompt and type cd \Ruby22
and press enter, then type ruby dk.rb init
. Next type notepad config.yml. A configuration file should pop up. Modify it so that it looks like the code listed below, then hit save.
# This configuration file contains the absolute path locations of all
# installed Rubies to be enhanced to work with the DevKit. This config
# file is generated by the 'ruby dk.rb init' step and may be modified
# before running the 'ruby dk.rb install' step. To include any installed
# Rubies that were not automagically discovered, simply add a line below
# the triple hyphens with the absolute path to the Ruby root directory.
#
# Example:
#
# ---
# - C:/ruby19trunk
# - C:/ruby192dev
#
---
- C:/Ruby22
Once that is completed, save and close notepad, then type the following command in the command prompt: gem update --system && gem update
and press enter. This will update RubyGems as well as the built in gems. It may take a few minutes depending on your computer and internet speed.
Installing Rails
Now we are ready to install Rails. Type gem install rails
in the command prompt and press enter. RubyGems will download and install Rails. However, we aren't done yet.
First thing we need to do is check the version of nokogiri installed. 1.6.6.2 and older versions do not function properly on Windows. If you are using a version newer (1.6.7) then you don't need to do a thing. Otherwise you'll need to update nokogiri to the RC version of 1.6.7. Check What the latest version is at the RubyGems website. As of this writing, 1.6.7.rc3
is the latest version. To install this version, type gem install nokogiri -v 1.6.7.rc3
. Make sure to change the version based on the one you see at the RubyGems website. This will install a functioning version of nokogiri, which will allow Rails to work.
Finally, type gem cleanup
to remove the old versions of gems.
Rails Application Setup
There is one more change you need to make and that is in the Gemfile of your Rails app. Open up your gemfile and add gem 'nokogiri', '1.6.7.rc3'
underneath the line that says source 'https://rubygems.org'
then save a file. Finally, run a bundle update nokogiri
from the folder where your application is located to update the version of nokogiri your app is using.
ExecJS::ProgramError
If you are getting this error, install Node.js fromThe Node.js website and close and reopen all of your command prompts.
SQLite
One more thing, problems with sqlite3? The latest version of the sqlite3 gem works perfectly with Ruby 2.2. If you are having issues, just run a bundle update sqlite3
.
You should now be all set. Our article, Rails Development on Windows - The Basics also has some good points on working with Ruby on Rails and Windows so be sure to check it out. If you get stuck, feel free to leave a comment below, but it's also worth posting at Stack Overflow. My time is limited, so I can't always reply to every comment, but I certainly try. That's it! Thanks for reading!