Last Updated: February 25, 2016
·
5.46K
· vladimirn

Ruby on Rails with MySQL Windows installation walkthrough

Here I will talk about downloading and installing Ruby on Rails for Windows. I usually work in Ubuntu, however my friend was eager to know how to install Ruby on Windows box, so here are the steps.

<b>1) </b>First of all download ruby installer from here: http://rubyinstaller.org/downloads/ Choose Ruby version that you like, however take in mind that if you are planing to work with RubyMine. version 2.0+ does not support regular debugger gems and pry debugger is not supported yet in RubyMine, so i would advise to use 1.9.3 version as the most stable Ruby version. Here is direct download:
http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-1.9.3-p545.exe?direct

<b>2) </b>Make sure during installation to check Add Ruby executables to your PATH and Associate .rb files options

<b>3) </b>Test ruby installation with ruby -v from cmd - it would print what version of ruby is installed

<b>4) </b> Download devkit from here http://rubyinstaller.org/downloads/ In case your are using 1.9.3 version get if from here: https://github.com/downloads/oneclick/rubyinstaller/DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe

<b>5) </b> Unpack it and navigate in cmd to devkit dir
run ruby dk.rb init to Initialize - it will generate config.yml file with ruby installations
run ruby dk.rb install

<b>6) </b>. Install RubyMine IDE from JetBrains (30 day trial) regular license costs 99$ and it really worth it. If you are used to developing in Visual Studio then download Saphire IDE from here: http://www.sapphiresteel.com/spip?page=download <br>
I won't cover installation of Saphire IDE since i myself use Ruby Mine and really advise you to do the same

<b>7)</b> Open Ruby Mine and create new project of Rails Application type. RubyMine will ask you to point to your ruby installation, so choose something like: F:\Dev\ruby-1.9.3\bin\ruby Choose Install Rails Gem from Rails Installation select box or run in cmd gem install rails and then choose installation.
select mysql for db, but take in mind that you will get errors on installation. Don't worry. we will fix them now.

<b>MYSQL setup</b>

Assuming you have MySQL installed on your Windows box residing in c:\Program Files\MySQL\MySQL Server 5.5

<b>1) </b> Download [libmysql.dll][1]. Copy the above libmysql.dll to
F:\Dev\ruby-1.9.3\bin AND F:\Dev\ruby-1.9.3\lib, or wherever your lib and bin are.

<b>2) </b> Open cmd and run: gem install mysql

Then run gem install mysql2 -- '--with-mysql-lib="c:\Program
Files\MySQL\MySQL Server 5.5\lib" --with-mysql-include="c:\Program
Files\MySQL\MySQL Server 5.5\include" --with-mysql-dir="c:\Program
Files\MySQL\MySQL Server 5.5"'

<b>3) </b> Open RubyMine project folder in cmd and run bundle install

<b>4) </b> Try to run your Rails application in RubyMine. it should start web server on localhost:3000, however if you navigate to host you will see an error "Cannot connect to MYSQL". Probably it's because your mysql process is not running. Go to cmd as Administrator and run the following:

cd C:\Program Files\MySQL\MySQL Server 5.5\bin
mysqld

You will still get an error, however it's because RubyMine sets up by default nonexistent db.

<b>Set up Database</b>

<b>1) </b> Create Dedicated DB in MYSQL - you can do it from your favorite tool or from cmd type:

<i>mysql</i>

<i>create database test</i>

<b>2) </b> navigate in your project to config/database.yml and set there user,password for database as well as database name
By the way in order to view your db inside the IDE you can open Database window: View->Tool Windows -> Database

<b>Set up the Debugger</b>

Stop the server and choose Run>Debug in RubyMine. It will ask you if you want to install debugger. confirm and wait for gem install to finish. Run Debug. You should be all set