Ruby on Rails in Cygwin May 24, 2011Posted by ficial in Blogroll, ruby on rails, techy.
Tags: cygwin, ld returned 1 exit status, rails, ruby, win32ole
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
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:
- 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)
- 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)
- 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
- change directory into the unpacked code:
$ cd ruby-1.9.2-p180/
- configure (30 minutes?):
$ ./configure --with-out-ext=win32ole
- make (1-2 hours? creates the compiled objects from the source code):
- install (makes everything work):
$ make install, then test (ruby -v)
- update the gem system:
$ gem update --system
- install rails:
$ gem install rails
- 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:
- exit all cygwin shells/processes
- run cygwin setup and choose ALL readline libraries/components (just to be sure)
- open a cygwin shell
$ cd ruby_install_directory/ext/readline
$ ruby extconf.rbthis should show, among other things:
checking for readline/readline.h… yes
checking for readline/history.h… yes
$ make install
and now rails c should work (at least, it does for me).