Click here to Skip to main content
15,867,308 members
Articles / Database Development / MySQL
Tip/Trick

Install Rails 4 and MySQL Server on Windows 7/8

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
22 Jul 2014CPOL4 min read 27.3K   5  
Install Rails 4 and MySQL Server on Windows 7/8

Introduction

Here are the stes for Installing Rails 4 and MySQL Server on Windows 7/8

Using the code

Install Rails 4 and MySQL Server on Windows 7/8

Watch the following video before installing:
http://www.globalnerdy.com/2013/10/25/how-to-install-rails-4-on-windows-including-windows-8-and-8-1/

other References:
i)   https://github.com/brianmario/mysql2
ii)  http://blog.mmediasys.com/2011/07/07/installing-mysql-on-windows-7-x64-and-using-ruby-with-it/
iii) http://learnwebtutorials.com/step-by-step-tutorial-on-installing-ruby-on-rails-4-on-windows-8

Installing Ruby, Rails and MySQL Connector

1) Install Ruby (32Bit Version Ruby 2.0.0-p451)

i) Download Ruby 2.0.0-p451 (32bits version only) from http://rubyinstaller.org/downloads
or download using url (http://dl.bintray.com/oneclick/rubyinstaller/ruby-2.0.0-p451-i386-mingw32.7z?direct)
Note: the 64 bit version of Ruby 2.0.0-p451 is not compactible with MySQL

ii) Choose the installation options as
1. Install tcl/tk support
2. Add Ruby executable to PATH
3. Associate .rb and .rbw files with Ruby

You can select all the options. But make sure you atleast select the 2nd option

iii) Confirm that Ruby is installed
After installation, see that
a) It saved ruby in C:\Programs\ruby200\
b) Added Ruby to the Windows PATH environment variable. 
c) Also see that a new Windows tile have been created on your start page that says “Start Command Prompt With Ruby”
d) Opne Command Prompt and run "ruby -v" ruby 2.0.0p451 (2014-02-24) [i386-mingw32]

2) Create Application Folder for your websites

Search for “Start Command Prompt With Ruby”. Click on that to get to the command prompt.
Now create a new folder in Windows at C:\Data\Sites

That will be the location of where we will place our Ruby apps.  
At the Command Prompt, it is best to navigate to this directory before typing Ruby commands.

3) Extract 32 bit DevKit (DevKit-mingw64-32-4.7.2-20130224-1151-sfx)

i) Download DevKit for Ruby 2.0 (32bits version only) DevKit-mingw64-32-4.7.2-20130224-1151-sfx from http://rubyinstaller.org/downloads
or download using url (http://cdn.rubyinstaller.org/archives/devkits/DevKit-mingw64-32-4.7.2-20130224-1151-sfx.exe)

ii) Extract the DevKit zip file into C:\Programs\Ruby200\devkit

iii) Navigate to C:\Programs\Ruby200\devkit and run following
a) ruby dk.rb init --force
b) ruby dk.rb review
c) ruby dk.rb install --force

iv) Test Installed DevKit(Optional):
On Command Prompt, run followings
a) gem install json --platform=ruby --no-ri --no-rdoc
b) ruby -rubygems -e "require 'json'; puts JSON.load('[42, 56, 22]').inspect"

4) Download & Extract 32 bit MySQL Connector/c

i) Browse to http://dev.mysql.com/downloads/connector/c/
Note:
a) Ruby uses the same connector that C uses.
b) Even if you have 64 bit MySQL Server, the connector should be 32 bit. The 32bit Ruby communicates to MySQL via this Connector.

ii) Click Looking for previous GA versions?
Note: The latest MySQL 6.1.3 connector is not compatible with Ruby

iii) select & Download Windows (x86, 32-bit), ZIP Archive (mysql-connector-c-noinstall-6.0.2-win32.zip)
Direct URL: http://dev.mysql.com/downloads/file.php?id=377978

iv) Extract mysql-connector-c-noinstall-6.0.2-win32.zip to C:\Programs\

5) Copy "libmysql.dll" from mysql/lib to ruby/bin folder

i) Copy libmysql.dll from C:\Programs\mysql-connector-c-noinstall-6.0.2-win32\lib to C:\Programs\Ruby200\bin

6) Install rails -v=4.0.2

i) On Command Prompt run,
gem install rails -v=4.0.2 --no-ri --no-rdoc

ii) Test the Rails Version installed by running "rails -v" in Command Prompt
Note: Rails 4.1.0 is not compactible with some libraries

7) Install mysql2

On Command Prompt run,
gem install mysql2 --platform=ruby -- --with-mysql-dir=C:\Programs\mysql-connector-c-noinstall-6.0.2-win32 --no-ri --no-rdoc

8) Install Other Gems(Windows 8.1 only)

On Command Prompt run,
gem install node --no-ri --no-rdoc

Installing My SQL Server

Install XAMPP OR My SQL Community Server

Browse to Url http://www.oldapps.com/xampp.php and download XAMPP 1.8.3-4
or download using direct Url: http://www.oldapps.com/xampp.php?old_xampp=14610

Install XAMP

OR

Install 32/64 bit MySQL Community Server

i) Browse to  http://dev.mysql.com/downloads/installer/5.6.html

ii) I installed MySQL Community Server 5.6 Windows (x86, 32-bit), MSI Installer  (mysql-installer-web-community-5.6.17.0)
url:  http://dev.mysql.com/downloads/file.php?id=451576
Note: you can install 64 bit version as well if you want


iii) Run the mysql-installer-web-community-5.6.17.0

iv) Click Add MySQL Products

v) Install Server Only option or Custom option with only MySQL Server 5.6.17 & Workbench selected.

vi) Select default and hit next. Keep other default option as it is and select next.

Testing Installation

1) Create new Ruby on Rails Site

On command prompt, navigate to C:\Data\sites\ and run
rails new <App Name> -d mysql -B
e.g.: rails new DemoApp -d mysql -B

ii) Test version of Rails in the new Site created
open Gemfile and make sure that the value of gem 'rails' is '4.0.2'

iii)update database.yml under config folder.
Update password. Enter Port: <port no> if port of MySQL is other than 3306.
Remove Test & Production section.

iv) On command prompt, cd to C:\Data\sites\<App Name> and run following  command,
bundle install


2) Test MySQL from newly created Ruby on Rails Site

i) On command prompt, cd to C:\Data\sites\DemoApp and run following one after another,

a) rake db:create
Note: Go to your MySQL and make sure that a database with name "DemoApp_Development" is created

b) rails g scaffold user first_name:string last_name:string email:string

c) rake db:migrate
Note: Go to your MySQL and make sure that a table Users is created in database "dbDemoApp"

d) Open command prompt and CD to sites.
rails s

e) On your browser, open http://localhost:3000/users and create new users.'
Note: Go to your MySQL and make sure that a table Users in database "dbDemoApp" has new users.

 

Thats it. Thank you.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) 3MD Tech
United States United States
Rocky Fernandes has over 11 years of experience in Software Industry mostly developing Web Applications. Other than having vast experience in various Microsoft Technologies like SharePoint, ASP.Net, C#, VB.Net, Silverlight, WCF, MVC, Web API, SQL Server, ADO.Net, ADOMD.Net, LINQ, Entity Framework, Exchange Web Service(EWS) API, he also has vast experience in Client Side Scripting like JavaScript, jQuery, JSON, JSONP, CSS and HTML5. He is very much passionate in programming and enjoys doing it. In the academic side he holds a BE Degree in Computer Science & Engineering. In the certification side he holds certifications in Sharepoint 2010, SharePoint 2013, ASP.Net & SQL Server.

In most of the free time, he will be spending in technical activities like researching solutions, reading technical articles and learning new stuff. He believes that following Best Practices and Coding standard is a way to go for producing an efficient, quality & satisfactory application.

Homepage: http://www.smartsolutionshub.com/

Comments and Discussions

 
-- There are no messages in this forum --