February 7, 2012

How to Install Ruby on Rails in Windows 8

Ruby on Rails has the best support environment in MacOS. It is also usable in Linux. And what about Windows? For me, someone who is familiar with Microsoft products and environment, the initial configuration is a little bit confusing although it is well documented.




Where to start

Of course, here: http://rubyonrails.org/download.

How to install Ruby

Follow the link from the Where to start section and install latest version of Ruby. The current version is 1.9.3 therefore you should use the rubyinstaller-1.9.3-p0.exe link. Install the application as usual. The first trap comes here. Check all the three boxes on the first screen (for some reason these are unchecked by default):

You can ensure the Ruby is installed correctly by opening PowerShell and type in "irb". If you see irb(main):001> you are in.

How to install Ruby Gems

Ruby Gems is something like a package manager. It is needed for Ruby on Rails installation. Follow the link from Where to start section and download the package (ZIP in my case). Unpack the package and run the setup.rb script. The .rb was registered during Ruby installation.

How to install Ruby On Rails

Open PowerShell and type in gem install rails. You will see something like this:

I have seen one error: file lib not found. What does it mean? I'm not sure but you can continue in instructions.

Make your application

Open PowerShell and type in (every line is a single command):
rails new path/to/your/new/application
cd path/to/your/new/application
rails server
You can use PowerShell for that.
Ouch. Trap number two!
I've got this message:
Gem::InstallError: The 'json' native gem requires installed build tools.
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'
An error occured while installing json (1.6.5), and Bundler cannot continue.
Make sure that `gem install json -v '1.6.5'` succeeds before bundling.

I've tried to install json this way: gem install json and I've got another error:
ERROR: Error installing json:
The 'json' native gem requires installed build tools.
Please update your PATH to include build tools or download the DevKit
from 'http://rubyinstaller.org/downloads' and follow the instructions
at 'http://github.com/oneclick/rubyinstaller/wiki/Development-Kit'

How to install Development Kit

From Ruby installers download the file DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe. Create a folder DevKit inside Ruby folder and unpack the downloaded package into this newly created folder. Then run:
devktivars.ps1
ruby dk.rb install
Now you can finally run command: gem install json.

How to install Ruby on Rails again

You know:
rails new path/to/your/new/application
cd path/to/your/new/application
rails server

Run server

http://localhost:3000
If you can see this screen:
that means you have succesfully configured Ruby on Rail in Windows!

What's next?

Locate your favourite editor and start with learning videos. There are two main possibilities for it: Vim for Rails and Rad Rails.

Rails Installer

Anonymous suggest that you can use Rails Installer. I didn't try it. Please write me your experiences with it into comments.

Personal message

I'm looking forward to next technical meeting about Ruby on Rails. Thanks, Radim!

7 comments:

  1. Very nice install instructions, got it all running the first time, well...on Win7 Home Premium I had to change the Powershell policy before I could run the devkit install.

    PS > Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

    Also, ruby wanted me to run init before install, for the DevKit, like:

    devktivars.ps1
    ruby dk.rb init
    ruby dk.rb install

    Otherwise, off to the videos and a new journey. Thanks again for this post.

    ReplyDelete
    Replies
    1. I was looking for this, THANKS! I'll give that a try on my Win 8!

      Delete
  2. You can install RoR on Windows in one step with http://railsinstaller.org/

    ReplyDelete
    Replies
    1. Thank you for suggeestion. I'll add it into article.

      Delete
  3. RailsInstaller. Problem solved

    ReplyDelete
  4. Thanks a lot for posting this brief tutorial! I ended up getting a LOT further in the installation process with your tips/tricks than I have during my 10 or so other attempts to get Ruby on Rails going. SO grateful! :)

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete