Life Of Navin

Random Musings, Random Bullshit.

kc

RoR On Windows With XAMPP!

Ruby is an Object-Oriented language that was born in the mid-90's, but gained popularity in the early 2000's. As the creator of the language Matz puts it: "Ruby is about making coding natural, not simple". And once you get used to it, Ruby really begins to feel natural!

One reason for Ruby's popularity is undoubtedly Ruby on Rails aka RoR, an open source Web Development framework for Ruby. The power of RoR lies in it's simplicity and speed of development! Many popular websites like Twitter, Hulu, Scribd, and Github make use of RoR (see this).

One must note that Ruby != RoR. They're totally different!

Hopefully, this short intro has gotten you interested in Ruby and RoR. So let's see how to setup Ruby and RoR on Windows systems! Why Windows? Because the install procedure for Windows is a bit of a pain in the a** compared to the install procedure in Linux. For this article, I'll be using a system running Windows 7.

Anyway, here's what you need:
  • The latest version of Ruby Installer (Get it from here)
  • The latest version of XAMPP (Get it from here)
Ruby Installer is a compact package containing the entire Ruby setup and all it's dependencies. Another thing included in Ruby Installer is Ruby Gems, which is a package manager. (At it's simplest, Ruby Gems is like the Add/Remove programs feature in Windows.... except that it deals only with Ruby components/modules (which are called gems) ).

So let's get started shall we?
  1. Double Click on the Ruby Installer executable and install Ruby into C:\Ruby



  2. Double Click on the XAMPP executable and install XAMPP in C:\xampp
  3. Go to My Computer-> System Properties->Advanced System Settings



  4. Choose the Advanced tab and then click on Environment Variables

  5. Check if C:\Ruby\bin is present in the Path row. If not present, select the Path row, click edit, and add C:\Ruby\bin; at the start.

  6. Open a Command Prompt and do the following:

    C:\>ruby -v
    ruby 1.8.

    C:\>gem -v
    1.3.7

  7. If you get this output (or something similar depending on the version of Ruby and RubyGem installed), you have Ruby and RubyGems installed successfully! So How about we get on the rails now, and install RoR?

    C:\>gem install rails --include-dependencies
    INFO: `gem install -y` is now default and will be removed
    INFO: use --ignore-dependencies to install only the gems you list
    Successfully installed rails-3.0.0
    1 gem installed
    Installing ri documentation for rails-3.0.0...
  8. Let us check if Rails is installed or not:

    C:\>gem list

    *** LOCAL GEMS ***

    abstract (1.0.0)
    actionmailer (3.0.0)
    actionpack (3.0.0)
    activemodel (3.0.0)
    activerecord (3.0.0)
    activeresource (3.0.0)
    activesupport (3.0.0)
    arel (1.0.1)
    builder (2.1.2)
    bundler (1.0.2)
    erubis (2.6.6)
    i18n (0.4.1)
    mail (2.2.7)
    mime-types (1.16)
    polyglot (0.3.1)
    rack (1.2.1)
    rack-mount (0.6.13)
    rack-test (0.5.6)
    rails (3.0.0)
    railties (3.0.0)
    rake (0.8.7)
    thor (0.14.3)
    treetop (1.4.8)
    tzinfo (0.3.23)

  9. Yeah! So we're all set with RoR! Now let's get XAMPP configured shall we? Go to C:\xampp\htdocs and create a new folder where your RoR project will reside. Let's name this folder Ruby.
  10. Now go to C:\xampp\apache\conf and open the file named httpd.conf with a text editor (I use Notepad++) and add the following right at the end of the file:

    Listen 3000
    LoadModule rewrite_module modules
    /mod_rewrite.so
    #################################
    #
    RUBY SETUP
    #################################
    <virtualHost *:3000>
    ServerName rails
    DocumentRoot "c:/xampp/htdocs/ruby/public"
    <Directory "c:/xampp/htdocs/ruby/public/"

    Options ExecCGI FollowSymLinks
    AllowOverride
    all
    Allow from all
    Order allow,deny
    AddHandler cgi-script .cgi
    AddHandler fastcgi
    -script .fcgi

    </Directory>
    </
    VirtualHost>


    Note the DocumentRoot and Directory line.... they must have the correct path of the folder that you created.
  11. Now we shall see the power of RoR. Go to the Command Prompt and type in:

    C:\Ruby\bin>rails new C:/xampp/htdocs/ruby -d mysql
    exist
    create README
    create Rakefile
    create config.ru
    create .gitignore
    create Gemfile
    create app
    create app/controllers/application_controller.rb
    create app/helpers/application_helper.rb
    create app/views/layouts/application.html.erb
    create app/mailers
    create app/models
    create config
    create config/routes.rb
    create config/application.rb
    create config/environment.rb
    create config/environments
    create config/environments/development.rb
    create config/environments/production.rb
    create config/environments/test.rb
    create config/initializers
    create config/initializers/backtrace_silencers.rb
    create config/initializers/inflections.rb
    create config/initializers/mime_types.rb
    create config/initializers/secret_token.rb
    create config/initializers/session_store.rb
    create config/locales
    create config/locales/en.yml
    create config/boot.rb
    create config/database.yml
    create db
    create db/seeds.rb
    create doc
    create doc/README_FOR_APP
    create lib
    create lib/tasks
    create lib/tasks/.gitkeep
    create log
    create log/server.log
    create log/production.log
    create log/development.log
    create log/test.log
    create public
    create public/404.html
    create public/422.html
    create public/500.html
    create public/favicon.ico
    create public/index.html
    create public/robots.txt
    create public/images
    create public/images/rails.png
    create public/stylesheets
    create public/stylesheets/.gitkeep
    create public/javascripts
    create public/javascripts/application.js
    create public/javascripts/controls.js
    create public/javascripts/dragdrop.js
    create public/javascripts/effects.js
    create public/javascripts/prototype.js
    create public/javascripts/rails.js
    create script
    create script/rails
    create test
    create test/performance/browsing_test.rb
    create test/test_helper.rb
    create test/fixtures
    create test/functional
    create test/integration
    create test/unit
    create tmp
    create tmp/sessions
    create tmp/sockets
    create tmp/cache
    create tmp/pids
    create vendor/plugins
    create vendor/plugins/.gitkeep

    If you now go to C:\xampp\htdocs\ruby, you should see something like this:


    These are all the files created automagically by RoR! Nice, ain't it?
  12. Start XAMPP and start the MySQL and Apache services:

  13. Open a browser (Read: Firefox! :) ) and type in http://localhost:3000 ... and you should see this page:

  14. That's it... you're now officially on the Rails! So now it's time to start developing you web apps with RoR!
Notes:
  • Gems are, in my opinion, the most powerful feature of Ruby. Gems are like modules that can easily be used in any project. I'd urge you to head over to this site, which holds over 16500 Ruby gems. Installing any gem is the same procedure as Step 7. Just type in gem install [gemname] to download and install the gem. You will probably need gems like mysql (gem install mysql), sinatra (gem install sinatra) etc. for web app development.
  • Yes, I know this is NOT the only way to install RoR. But I use XAMPP for almost everything so have included it here as well! This procedure should ideally work with WampServer as well, as long as the paths are corrected.
  • By default, RoR assumes that your MySQL root password is absent. However if you have assigned a root password, you must change the database.yml file present in C:\xampp\htdocs\Ruby\config.yml . Also, RoR recommends the creation of 3 databases: One each for testing, development and production. By convention they are named as [projectname]_test,[projectname]_production and [projectname]_production. You will have to create these databases externally through MySQL or using rake db:migrate. If you prefer to use alternative names, simply modify the config.yml file with names of your choice!
  • RoR on Windows really is a bit of a pain, and may not even work the first time! Honestly, I believe any serious developer must be comfortable working in Linux, which is more suited to the need! RoR on Linux is a breeze and works great (if not better)!
So far, I'm having an awesome time on Rails and am looking forward to working more in RoR! Hope you too enjoy the trip on rails! :)

26 comments :

Sathya said...

Why not use built-in WEBrick ?

rails server will start the server. After all, it's for localhost testing

navinpai said...

@Sathya Actually I use Mongrel almost all the time.

In college, we're just beginning with RoR , and I wanted people to be comfortable with the XAMPP/WAMP setup that we've been using so far! This post was actually written specifically for my college mates! :)

Infact one of the reasons I chose to have this post specific to a Windows system was because most of my collegemates use Windows! :)

Sathya said...

I understand that this is a Windows centric post, my comment was also Windows centric :)

Using the default server means you don't need to spend that extra time configuring XAMPP/WAMP.

( Sidenote: RoR on Windows is a pain, especially if you're going to work with Heroku. Be prepared to ear your hair out)

lafosse-john said...

This is the only tutorial that has worked and made sense to me. Thank you. I spent all day trying to get this running. It is really easy.

lafosse-john said...

This is the only tutorial that has worked properly. Thank you!!
I spent all day trying to Ruby and Rails running.

Quick Question? I added port forwarding for port 3000. Is that something you should add?

Nag said...

Thank you very much. I tried in many ways to install ROR with xampp in my PC by reading many articles and blogs. But no use for me. Now i installed successfully ROR with xampp by reading your article.

Your article helped me a lot.

Thank you Navin.

raj said...

it works for me until this dude. but when I click on the "About your applications environment" it gives me a object no found error. I couldn't navigate o any of the controller views I am creating

Nirmesh Rastogi said...

There is a typo in ur code directory tag should be closed it took me hours to figure it out anyways keep up the good work

Der Bruchköbeler said...

The Apache configuration (point 10 of your description)is not proper working. Take the following two parts and don't forget to change pathes of the document root.
Just add a Listen 3000 down the line where Liste 80 is located. Then place the two following two hosts at the end of the config.http.


ServerName localhost
DocumentRoot "c:/xampp/htdocs"
ErrorLog "logs/localhost.error.log"
CustomLog "logs/localhost.access.log" combined



ServerName rails
DocumentRoot "c:/xampp/htdocs/ruby/public"
AddHandler cgi-script .cgi
AddHandler fastcgi-script .fcgi
ErrorLog "logs/rails.error.log"
CustomLog "logs/rails.access.log" combined

Options ExecCGI FollowSymLinks
AllowOverride all
Require all granted

Anonymous said...

Nice post.
i'd followed your steps but one little problem when i browse it the rails logo doesn't show.
any suggestion would be greatly appreciated.
thanks before.

Anonymous said...

Nice post.
i'd followed your steps but one little problem when i browse it the rails logo doesn't show.
any suggestion would be greatly appreciated.
thanks before.

Unknown said...

Awesome post! Thank you! This was really helpful. I'm also having the same issue as the last person that commented the Rails logo is not showing. I already tried changing the path from assets/rails.png to background-image: url("../assets/images/rails.png"); but nothing seem to work. :-(

FREE SOFTWARE DOWNLOAD said...

thank you for this ruby on rails trick.....
FREE SOFTWARE DOWNLOAD | FULL VERSION SOFTWARE

Zinavo-Web Design | Web Development | SEO | Mobile Apps | ERP/CRM said...

Good post! really its very useful for beginners. Website Designing Company Bangalore | Web Development Company Bangalore

Yasir Jamal said...

I agree with all of the points keep up the good work.Thanks for sharing this.
Wordpress developer in dubai

Unknown said...

Fantastic script!Very rich ideas with clear illustration to get some tips thanks for sharing
dubai podiatrist

Ancy merina said...
This comment has been removed by the author.
Unknown said...

C:\xampp\htdocs\Ruby>rails server
Failed to load libmysql.dll from C:/Ruby/lib/ruby/gems/2.5.0/gems/mysql2-0.5.0-x64-mingw32/vendor/libmysql.dll
ganerate erroe on server start

POS One Systems said...

One of the best programming language for creative web development. RoR is the first choice of our in-house software development team who love to work with Ruby.

rohit said...

Nice post, many of the important things you share here. website design company in mumbai, website development company in mumbai"

Tejuteju said...

After reading this blog I very strong in these topics and this blog really helpful to all Ruby on Rails Online Course Bangalore

Technobizzar - Website Design Company In Mumbai said...

Nice post, thanks for sharing with us this kind of important information with us. web designing company mumbai | web developer in mumbai | web maker in mumbai

Anonymous said...

Greats thanks for sharing the content www.digifutura.com is the best web app development company

Anonymous said...

Great thanks for sharing the content but https://www.digifutura.com is the best web development company in usa

web design company Dubai said...

Excellent and decent post. I found this much informative, as to what I was exactly searching for. Thanks for the post and please keep it up. You did a great job and thanks for sharing.

Houses for sale in bahria town karachi said...

Splendid post. Also visit here: Feeta.pk Houses for sale in Peshawar . it is very helpful for us thanks for sharing.

Prologue

Finally after all these years, here's to the beginning of what was there, what is there and hopefully what will remain!! So here are my thoughts & words -Online!!

Blog Archive