jump to navigation

Ruby on Rails in Cygwin May 24, 2011

Posted by ficial in Blogroll, ruby on rails, techy.
Tags: , , , ,

I’ve spent way too long trying to get ruby on rails running in cygwin for my work windows machine (XP, yes, I know it’s way behind the times; I’m expecting an upgrade to windows 7 soon). Most guides suggest using RailsInstaller for work in a windows environment, and RVM for elsewhere. Cygwin (essentially a linux emulator that runs in Windows) comes with ruby 1.8.7 if you include that package in the set up, but I wanted the latest version (1.9.2-p180) because there were some significant changes between 1.8.7 and 1.9.2.

The main difficulties I’ve run into are that the various install instructions I’ve found on the net don’t work – the install fails and the instructions don’t cover that possibility and it’s been difficult to find any leads as to what went wrong and how to fix it. Finally, I figured it out, and shortly thereafter found a helpful page that would have pointed me in the right direction had I found it earlier. So, I’m writing this up in hopes that it will save someone else some time and pain.

Getting the latest (1.9.2) version of ruby running in cygwin was not working using RVM nor was installing directly from source. The process would repeated fail (on Windows XP and Windows 7) in the make process at the step of compiling the win32ole extension, with an error message of

collect2: ld returned 1 exit status
make: *** [../../.ext/i386-cygwin/win32ole.so] Error 1

For what I need (a rails dev environment) the win32ole extension seems unnecessary, and with a bit of experimenting I discovered that I could install ruby from source and just delete the ext/win23ole folder before doing ./configure; make; make install (which, for those less familiar with linux, is the standard command sequence to compile code from source and install the result on your system). Then the make process would run smoothly and the rest of the rails installation worked fine.  After finding and reading a relevant stack overflow discussion  I learned that the configure script would take and option to exclude extension, so the preferred approach is to use

./configure --with-out-ext=win32ole

I could not find a way to tell RVM to use configuration options, so I still couldn’t use it to install ruby 1.9.2; installing from source was the only option that worked for me.  So, in summary:

  1. install cygwin, WITHOUT ruby (to avoid version conflicts; I’m guessing you could install RVM after all this to manage which version was active, but I haven’t experimented with that and generally find it safer just to avoid any potential conflicts – feel free to leave more info about this in the comments if you have any experience with it). NOTE: you will need some development packages/libraries – curphey has a good summary of what you’ll need. ALSO NOTE: the cygwin install process can take several hours (most of which you can spend away from the computer)
  2. get the latest ruby source (tgz version), then copy it to your cygwin home directory (if you use the cygwin defaults then it’ll be C:\cygwin\home\username)
  3. open a cygwin command line (I like the mintty terminal, but any of them will work) and unpack the source: $ tar xzf ruby-1.9.2-p180.tar.gz
  4. change directory into the unpacked code: $ cd ruby-1.9.2-p180/
  5. configure (30 minutes?): $ ./configure --with-out-ext=win32ole
  6. make (1-2 hours? creates the compiled objects from the source code): $ make
  7. install (makes everything work): $ make install , then test (ruby -v)
  8. update the gem system: $ gem update --system
  9. install rails: $ gem install rails
  10. and so on

Basically, everything after the configure –with-out-ext=win32ole step matches existing instructions and guides and works as far as I’ve tested it (so far, up through putting an app into source control on github). Good luck, and feel free to share additional info in the comments.

ETA 2011/08/09: making sure rails console works!

I just ran into a problem with my set up where I couldn’t use the rails console because the system couldn’t find readline: “/usr/local/lib/ruby/1.9.1/irb/completion.rb:9:in `require’: no such file to load — readline (LoadError)”, which was strange because I knew I’d included readline when choosing which cygwin pieces to load. However, it turns out that the version of readline matters very much here. I’d had versions 6 and 7 installed, but I needed 5 to make rails happy. So:

  1. exit all cygwin shells/processes
  2. run cygwin setup and choose ALL readline libraries/components (just to be sure)
  3. open a cygwin shell
  4. $ cd ruby_install_directory/ext/readline
  5. $ ruby extconf.rb this should show, among other things:
    checking for readline/readline.h… yes
    checking for readline/history.h… yes
  6. $ make
  7. $ make install

and now rails c should work (at least, it does for me).



1. Eric Sorenson - July 15, 2011

Thanks for the great post! Exactly what I was looking for.

2. Alex - February 7, 2012

So the best way to have rails running through cygwin is to pretty much scratch railsinstaller? Is there any way to force cygwin to launch rails from the railsinstaller path, rather than installing a whole new instance of ruby?

ficial - February 8, 2012

I didn’t have any luck except for the way documented above – others who are more proficient with the cygwin environment may get it to work some other way.

That being said, once I finally figured out what I needed to do, installing a new instance of ruby took a while but wasn’t too difficult or complicated.

3. Jon Wolski - March 15, 2012

Regarding your update, I had a similar issue with yaml. Without resolving, I could not “gem install rails” for lack of “psych”

I built and installed libyaml, and then followed your procedure for readline.

$ cd ruby_install_directory/ext/psych
$ ruby extconf.rb
$ make
$ make install

gem worked after that.

4. Jerry - April 19, 2012

For what it’s worth, and thanks to

http://stackoverflow.com/questions/9673477/error-dealing-with-rails-in-aptana and


you might try the following aliases in your ~/.bash_aliases or ~/.bashrc

alias gem=’C:/Ruby193/bin/gem’

alias ruby=’C:/Ruby193/bin/ruby’

alias rails=’C:/Ruby193/bin/rails’

# alias irb=’/cygdrive/c/ruby/bin/irb.bat’

alias irb=’C:/Ruby193/bin/irb.bat’

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: