I had some problems installing Ruby on Rails on Windows 8 so I'm writing this down as a summary.
You might also want to read the most recent post on the same topic.
- Use RubyInstaller. I recommend version 1.9.3. With version 2, I run into various problems trying to build native gems (e.g. libiconv not found). By default this will install Ruby at C:Ruby193. I also recommend selecting the Add Ruby to the PATH during installation, no need to do it manually later.
- From the same site, download DevKit. It's a self extracting archive and you need to extract it to its final location. I extracted it under C:Ruby193devkit so it's together with ruby.
- Install DevKit: from a command prompt, go to C:Ruby193devkit and run
ruby dk.rb initand then
ruby dk.rb install
- Update gem to latest and greatest with
gem update --systemand then
- Install rails with
gem install rails
- Install sqlite3 with
gem install sqlite3
So far so good. At this point we're ready to start going through the tutorial Getting Started with Rails to create our first application. Let's to that with the command
rails new blog.
Among other things in the output, you'll notice that some gems are already present (e.g. json, rails) while others are being installed at that moment (e.g. execjs, coffee-script).
Installing coffee-script-source (1.6.2) Installing execjs (1.4.0) Installing coffee-script (2.2.0) Using rack-ssl (1.3.3) Using json (1.7.7) Installing rdoc (3.12.2) Using thor (0.18.1) Using railties (3.2.13) Installing coffee-rails (3.2.2) Installing jquery-rails (2.2.1) Using rails (3.2.13) Installing sass (3.2.7) Installing sass-rails (3.2.6) Using sqlite3 (1.3.7) Installing uglifier (2.0.1) Your bundle is complete!
We can run the application at this point with
rails server and indeed it will load the default index.html. Following the tutorial, we can create our first home controller and delete the index.html. The command to do that is
rails generate controller home index. You also need to delete index.html and setup home#index as the default route.
This is where I had most of the problems. Instead of seeing my hello world message in this very simple controller, I ended up with the following error message in the command prompt:
And this is the error message that the browser showed:
You have to modify the file runtimes.rb (assuming you've kept the default paths, it is under C:Ruby193librubygems1.9.1gemsexecjs-1.4.0libexecjs) and find the block that declares the JScript external runtime (that's Microsoft Windows Script Host) and change it into this:
JScript = ExternalRuntime.new( :name => "JScript", :command => "cscript //E:jscript //Nologo", :runner_path => ExecJS.root + "/support/jscript_runner.js", :encoding => 'UTF-8' )
After this change, my hello world controller worked. I've tried the above procedure in both Windows 8 32 and 64 bits. I was also able to follow the tutorial a bit more by generating the post scaffold and I didn't run into any problems with sqlite, it seems to work. I stopped at the point where he adds a second model, so I don't know if there are any further pitfalls ahead…