How to install Ruby 3 on rails in Windows 7
This is a step by step tutorial that will let you succesfully 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.
- 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”.
- After installing Ruby, open CMD and check if you Ruby is accessible by executing the following command:
If it works fine you should see the version number of Ruby
- Then check if you can access gem command by executing:
- 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
- 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
- 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:
- Now you should install SQLite gem:
gem install sqlite3-ruby
- 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
- 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
- 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
- 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.ymlfile and replace every instance of “mysql2″ by “mysql”. Then save the file.
database.ymlis located at the config dir of the new project tree.
- Now it is time to modify the
Gemfilewhich is located at the root of the project tree.
Once edited, you should also replace “mysql2″ by “mysql”.
- 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'
- 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
- After this, from the root of your new project, you are ready to execute:
- 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
- Then, we perform actual changes into the DB by executing:
- Finally, let us run the Rails httpd server:
- Open your browser and go to:
http://localhost:3000/users, you should see the users list ready to add, edit and remove records.
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 ;)