Setting up Ruby (and Rails) on Windows 7 via Cygwin

I thought I’d post this here as it may be of value to some of the DJ Coding Course Cohorts (that’s a mouthful!), amongst others and it seems to fit more naturally here than it does on my other blog(s).

I’m not going to dive into anything in any more detail than is required to get the installation up and running; I’m presuming you’ll be able to Google for more information where necessary! 🙂

1. Install Cygwin –

Cygwin is essentially a port of the GNU Development Tools to Windows and gives you access to a *NIX-like environment (and shell), which you can use to run applications and tools such as Ruby.

Install Cygwin with the default packages, then go back and search for ‘curl’ and add it to your installation (the ones under Libs and Net – libcurl4 and curl respectively). Curl (cURL) is a program you can use to transfer data to or from a server (essentially).

Put the Cygwin installer somewhere it will be found in your path – the default install path is c:\cygwin64 (presuming you are on x64), so I put it in c:\cygwin64\usr\local\bin (am happy for someone who has used Cygwin more extensively to correct me on this).

2. Install RVM

Enter this at your cygwin shell prompt:

curl -sSL | bash -s stable

I found that this didn’t always work reliably and is actually an alias, so you may need to run this instead:

curl -sSL | base – s stable

If you see a warning about ~/.profile, then do:

source ~/.profile

3. Install Ruby 1.9.3

Don’t worry about the fact that the latest version is 2.1.2 – I had real problems with this on windows!

Launch your nice new Cygwin shell and enter:

rvm install 1.9.3

This is going to take a while and you’ll probably get a few different prompts, e.g. administrator permission for downloads, firewall access, etc. Agree to them, or it’ll fall down and go boom. You may also see the cygwin installer pop up and start downloading more files – this is normal.

The first time I ran it, it failed, and after about ten seconds of thought, I ran it again. It seems that sometimes cygwin doesn’t manage to download all the requirements before the process continues. While testing these instructions on my laptop, I actually had to run the installation a few times (3 to be precise), waiting for the cygwin installer to finish downloading each time.

The installation can take quite a long time (as it will likely have to build your Ruby installation from scratch), so be patient!

Once it completes, it will tell you how to build documentation. Don’t. It won’t work. Just look it up online instead!

4. Install Rails

Close your cygwin terminal (or type ‘exit’ to do so), and open a new one – this is important or the next step wil not work.

To select Ruby 1.9.3, do:

rvm use 1.9.3

Then enter:

gem install rails

This will download and install Rails – and all it’s requirements – which can take a while.

You will also need to install sqlite. Run the cygwin installer, search for “sqlite” and select the items under ‘Database’ and ‘Devel’ to be installed. Once this completes, run:

gem install sqlite3

In order to prove that rails is working (and to work out a few kinks), let’s quickly set up a test app:

rails new test-app

cd test-app

rails server -p 8080

This starts the Rails webserver (Rack) on port 8080 (I have stuff running on loads of ports, I believe the default is 3000, which may be fine for you).

If you then visit http://localhost:8080/ you should see the ‘Welcome aboard’ page.

5. Tweak execJS

A couple of small tweaks are required to keep things happy once you start generating controllers and models. Open up your equivalent of c:\cygwin64\home\mattc\.rvm\gems\ruby-1.9.3-p547\gems\execjs-2.2.1\lib\execjs\runtimes.rb and around line 41, you will see:

JScript =
name: “JScript”,
command: “cscript //E:jscript //Nologo //U”,
runner_path: ExecJS.root + “/support/jscript_runner.js”,
encoding: ‘UTF-16LE’ # CScript with //U returns UTF-16LE

Change this to:

JScript =
name: “JScript”,
command: “cscript //E:jscript //Nologo //U”,
runner_path: ExecJS.root + “/support/jscript_runner.js”,
encoding: ‘UTF-8’ # CScript with //U returns UTF-16LE

And finally, once you do create controllers, scaffolds – or anything else, you’ll need to edit app/assets/javascripts/application.js to delete these lines:

//= require turbolinks
//= require_tree .

They’re not essential (as far as I can tell) and I just couldn’t get it to work with them enabled – will try again when I have more time!

Good luck – and let me know if you run into any problems.

By Matt Chatterley

Matt is a Software Developer / Architect (and an aspiring Author and Speaker, too).

Comments (2)
  1. Rob 28th August 2014 at 22:05

    Great walk though Matt. One quick tweak, might be worth changing e: to c: as that will be most people’s default.

    Gonna give this a go on a Win 7 VM tomorrow and will feedback further if I come across anything else 🙂

    • Matt Chatterley 29th August 2014 at 06:51

      Thanks Rob – you’re right, I’ve edited the post to change example paths to c:\, was a bit fried last night! Let me know if I’ve missed anything, you find any other hiccups or anything needs clarifying – although I haven’t used the install heavily yet, it got a simple ‘Hello World’ Rails app running, so think it’s mostly there.

Leave a comment