↓ Archives ↓

Ruby on Windows

Some posts just write themselves. Today’s post comes from my reply to a guy in PhRUG who still thinks you need a Mac before you can develop Rails applications.

windows and ruby

The biggest problem the Ruby/Rails community has when trying to spread the word in this country: the lack of interest in supporting Windows.

I mean, a typical response to the legitimate question “I’m using Windows, how to I practice RoR?” is the fanboy answer: “Get a Mac!”

And that, my dear readers, is a dick move. If I was an average college student and you told me that, I’ll immediately think “WTF?!? I just want to try out this open-source language and web framework and I need to shell out a couple of years worth of tuition?!?

Answering “Format your hard drive and install Linux” is less of a dick move, but a dick move nonetheless.

Thus, if we rubyists want to spread the word about Ruby, we’ll have to make Windows a viable OS for Ruby development. Here are a few options available to us:


Use Ruby 1.9.2

Startup speed is probably the main problem with developing Rails in Windows. Fortunately, Ruby 1.9 is a heck of a lot faster than 1.8 thanks to the new interpreter.

I tried to install Rails 3 on my gaming rig just now to see the difference.

  • Downloaded and installed the 1.9.2 installer from the official ruby site. Note that you must tick the Add Ruby executables to your path to remove the need for doing that later.

ruby installer

  • Went to the command prompt (I used PowerShell because it’s just better) and installed Rails 3 using the same command for installing it in Linux or OS X: gem install rails --no-ri --no-rdoc

installing rails

  • Downloaded SQLite3 Windows DLL from the official download page and extracted it to the Ruby bin directory (use gem env to determine the path)

gem env

  • Created the 6-command blog program. (cd blog not included in pics)

rails new blog

bundle install

rails generate scaffold

rake db:migrate

rails server

  • Opened http://localhost:3000/entries in a browser. Works as expected.

open browser

Conclusion: Ruby 1.9 on Windows is pretty fast. Have the newbie install this along with NetBeans or RadRails and he should be diving into Rails in no time.

Virtualization (my personal choice)

virtual machine

The problem with Windows is that some important gems (rvm, unicorn, and passenger) are not supported by the OS. Fortunately, with a decent computer, you can run Linux inside of Windows without having to dual boot. VirtualBox or VMWare Player are both free virtualization options available on Windows.

For a gaming level rig (~4 GB RAM, RAM is pretty cheap nowadays), installing Ubuntu Desktop 10.4 (Lucid Lynx) on a VM with 10GB of space and 1GB of RAM should be more than enough for development needs. If you want to use a Windows editor/IDE to edit your files, you can setup shared folders to gain access to the files from the host PC.

For a slightly weaker machine, you could install Ubuntu Server on a VM with 10GB of space and 512MB of RAM, and voila! instant VPS on your PC. You can even use openssh-sever + PuTTY to emulate having multiple terminal windows.

JRuby

Pretty much the same as MRI Ruby with some minor differences. We don’t have rvm on Windows so you’ll have to change all of your “ruby” commands with “jruby” and prefix your ruby system commands with “jruby -S” e.g. “jruby -S gem ...“.

Downside is that it has the slow startup speed of 1.8 (they say you could tweak it to preload the libraries faster, but I haven’t tried it myself) and the native extension problems of having a different environment.

On the plus side, it’s on the JVM: just package your project into a WAR file with Warbler and it should be deployable on any J2EE application server. Great for convincing J2EE software houses to try out Rails.

In closing, if you’ve got a MacBook Pro and someone asks you about developing Rails on a PC, don’t be a dick and tell them “Get a Mac!”. Ruby is just fine regardless of whether you’re using Windows, Linux, or OS X.

This post by Bryan Bibat is from existence, refactored.

  • http://blog.mmediasys.com Luis Lavena

    Hello!

    Thank you for writing down this article! I believe too that for Ruby, acceptance of Windows as a platform should be addressed and developers should encouraged to consider it and support the users.

    I have one comment in relation to PowerShell usage. Please note that batch files for gems like rake, rails and others might not work as expected under it.

    If you want better copy and buffer capabilities than the default cmd.exe, you can wrap it around Console2 (available on SourceForge)

    See our group for details and possible issues with PowerShell usage:

    http://groups.google.com/group/rubyinstaller/

    Thank you again for your article, feel free to add it to our Wiki:

    http://github.com/oneclick/rubyinstaller/wiki/Tutorials

    Cheers!

  • http://blog.mmediasys.com Luis Lavena

    Hello!

    Thank you for writing down this article! I believe too that for Ruby, acceptance of Windows as a platform should be addressed and developers should encouraged to consider it and support the users.

    I have one comment in relation to PowerShell usage. Please note that batch files for gems like rake, rails and others might not work as expected under it.

    If you want better copy and buffer capabilities than the default cmd.exe, you can wrap it around Console2 (available on SourceForge)

    See our group for details and possible issues with PowerShell usage:

    http://groups.google.com/group/rubyinstaller/

    Thank you again for your article, feel free to add it to our Wiki:

    http://github.com/oneclick/rubyinstaller/wiki/Tutorials

    Cheers!

  • http://www.bryanbibat.com Bry

    Thanks for the response, Luis!

    BTW, we’re planning to hold Ruby and Rails workshops in local colleges here in the Philippines and we’re thinking of building self-contained Rails installers (think Instant Rails but with Rails 3 and SQLite) because these schools primarily use Windows and usually don’t have fast internet access.

    Can we fork the RubyInstaller project to build these installers? Also, would we encounter problems (legal or otherwise) if we package Rails and SQLite together with Ruby?

  • Anonymous

    Interesting,

    I have no personal objection on these packages. As InstantRails, these can be delivered to users as long source code is also available.

    As for the installer, I would recommend use the 7zip package as base, install the gems in it using that version of ruby with “–no-ri –no-rdoc –env-shebang” and then package as the installer.

    The 7zip packages will be better so you we are not distributing different versions of Ruby everywhere, also the customization of the installer itself to note your work.

    If you don’t mind, join us at RubyInstaller group:

    http://groups.google.com/group/rubyinstaller

    I see lot of potential from your v0 installer to become the next “InstantRails” alternative.

  • http://drnicwilliams.com drnic

    Top tip for virtualisation: http://vagrantup.com/ Very nice project if you like a VM on your windows machine.

  • https://www.google.com/accounts/o8/id?id=AItOawnLVdigqSwuoZz0R8TuCFuFMoZE0hXrVb4 arscariosus

    Hello, it’s nice to see that there are a lot of Ruby hackers in the Philippines now. I’m also a Filipino, an undergrad student that’s been learning ruby core and rails through online materials even though it’s not included in our curriculum. As for my comment proper to this post, it’s annoying to work with Rails on Windows since it’s so noticeably slow. So students like me end up using *nix and or buying a Mac if the budget allows. The sluggishness is bearable with Ruby core (solving competition materials and small MPs) but with Rails, it sucks. Various blog posts and forums have mentioned that there’s something wrong with Windows itself, so we can’t do anything about it, the best thing we could to is to set up a VB. :( I know this because I have this fascination with netbooks (even though netbooks might not be designed for development) because of their small form factor, and using the same hardware I’ve worked with small projects with Rails, and it definitely crawls natively on Windows, but on Ubuntu and my old Power Mac G4, it works great.