How to install Ruby 3 on rails in Windows 7

Introduction

This is a step by step tutorial that will let you successfully install Ruby on rails 3 in your Windows 7. The main objective was to ease the installation process which is kind of harsh and bumpy.

Procedure

  1. Download Ruby Windows installer from this URL.
    Select version 1.8.7, which is the most recommended and stable release for Windows.When installing this software, make sure to check “Add Ruby to PATH”.
  2. After installing Ruby, open CMD and check if you Ruby is accessible by executing the following command:
    ruby -v
    If it works fine you should see the version number of Ruby
  3. Then check if you can access gem command by executing:
    gem -v
  4. As you will see, probably the gem version installed by default is not the latest,
    so you should proceed to update gem like this:
    gem update --system
  5. Now it is time to install Ruby on rails. Rdoc and Ri documents the gems.
    NOTICE: It is well known that there is a bug when generating documentation for some of the gems needed for rails. Since Rails will work without it, let us avoid it until a new solution is published. 
    So you should execute:
    gem install rails --no-ri --no-rdoc
  6. Ruby on rails works with SQLite by default but we will use MySQL.
    In order to let you use both, let us download SQLite and then configure MySQL.
    Download SQLite dlls from here this URL,
    unzip them and copy them to:
    c:\<your_ruby_dir>\bin
  7. Now you should install SQLite gem:
    gem install sqlite3-ruby
  8. Now it is time for MySQL. Go to the MySQL website and download the community edition and after installing it in your OS, download this libMySQL.dll and copy it into the same location you put the SQLite dlls
    c:\<your_ruby_dir>\bin
  9. Now install the MySQL gem.
    NOTICE: Since it is also well known that there is a bug related to mysql2 on windows, please avoid it until they find a proper solution. There are additional procedures to make it work but as I assume that all you would like is to have a functional RoR in your Windows for development (not deployment), save the pain.
    To install the msyql gem execute:
    gem install msyql
  10. Now we are ready to create a testing project in rails.
    Since we are going to use MySQL as DB, we should then execute:
    rails new testproject -d mysql
  11. After creating the project, we must perform the following changes to make it work
    with mysql instead of mysql2 (which gets set by default).
    So please edit the database.yml file and replace every instance of “mysql2″ by “mysql”. Then save the file.
    Remember that database.yml is located at the config dir of the new project tree.
  12. Now it is time to modify the Gemfile which is located at the root of the project tree.
    Once edited, you should also replace “mysql2″ by “mysql”.
  13. Since there is another issue with rake 0.9, you should also replace the rake reference at the same file (Gemfile), by this more stable version:
    gem 'rake', '0.8.7'
  14. Now you should uninstall rake 0.9 and install rake 0.8.7, so you should execute:
    gem uninstall rake
    gem install rake –v 0.8.7
  15. After this, from the root of your new project, you are ready to execute:
    bundle install
  16. Relax, we’re almost there. You should now try to create CRUD operations for a simple user table. So let us execute:
    rails generate scaffold user name:string email:string
  17. Then, we perform actual changes into the DB by executing:
    rake db:create
    rake db:migrate
  18. Finally, let us run the Rails httpd server:
    rails server
  19. Open your browser and go to: http://localhost:3000/users, you should see the users list ready to add, edit and remove records.

Final comments

If you have followed this tutorial step by step you should be fine, if not let me know. As I said it took me a while to make it all work so I am sharing this in order to save your time, enjoy

Leave a Reply