Ruby on Rails on Windows 7 using Cygwin

If you’re already familiar with the terminal window environment on Mac OS or Linux, here is how to setup a similar environment on Windows 7 using Cygwin.

Install Cygwin

  • Download setup.exe from from the Cygwin install page. Make note of where you save it. In fact, life will be easier if you copy it to the desktop.
  • Choose ‘Install from Internet’ on 2nd page of installer dialog.
  • Install for ‘All Users’ and use the default ‘Root Directory’.
  • For ‘Local Package Directory’, you may take the default, but I prefer Downloads over Desktop.
  • Pick an appropriate mirror. No guidance is given on mirror location except some mirrors use country specific domain names. If unsure, US and Canadian users should pick sites ending with ‘com’, ‘net’, ‘org’, or ‘ca’.
  • Use the search dialog to find and add the following packages. This is easier if you use the View button on the right to switch the display mode to full. Use the leftmost column of the display to toggle. Note: Some packages have similar names. Select exactly these packages:
    • git
    • git completion
    • vim
    • rxvt
    • ruby
    • wget
    • patch
    • make
    • gcc
    • libsqlite3-devel
    • libxml2-devel
    • libxslt-devel
  • Allow Cygwin to create a Desktop icon on completion.

Configure Cygwin

  • For reasons that aren’t clear to me, I needed to do the following from a Windows command prompt. Note the prompts are included for clarity.
    C:\>cd \cygwin\bin
    C:\cygwin\bin>ash
    $ /bin/rebaseall
    $ exit
    C:\cygwin\bin>exit
    
  • Right click the Cygwin shortcut and choose edit from the menu. Change the contents to match:
    @echo off
    C:\cygwin\bin\rxvt -sr -sl 1500 -e C:\cygwin\bin\bash.exe --login -i
  • Double click the Cygwin shortcut. It should launch a bash shell which can be maximized to fill the screen. The current directory should be your Cygwin home directory. Most commands after this point should be run from the bash shell. NOTE: The paste function in this window is Shift-LeftMouseClick.
  • Use `vi .vimrc` to edit your vim configuration. Here’s what I use:
    set showcmd
    set showmatch
    set ignorecase
    set smartcase
    set incsearch
    set hidden
    set autoindent
    set backup
    set ruler
    set expandtab
    set tabstop=2
    set shiftwidth=2
    filetype plugin indent on
    set spellfile=~/.vim/spellfile.add
    set spelllang=en_us
    syntax on
  • Use `vi .bashrc` to examine your bash config and uncomment whatever aliases you typically use.
  • Use pwd to check your home dir. If the name contains a space, you may wish to rename it.
    cd /home
    mv <oldname> <newname>
    vi /etc/passwd

    The last line in /etc/passwd should be your account, likely with 3 occurrences of your name. Change the first and last to match the new name from the `mv` command above. I haven’t tested what happens if your change the middle one but I bet it’s something bad. After saving your changes, exit from all terminal pages so the new setting can take effect.

Install Rubygems

wget http://rubyforge.org/frs/download.php/74445/rubygems-1.6.2.tgz
tar -xzf rubygems-1.6.2.tgz
cd rubygems-1.6.2
ruby setup.rb

Install Rails

  • gem install rails

That should be it! I’ll continue to update as I learn better ways to do this.

This entry was posted in Ruby on Rails. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>