Have you tried setting up decent Ruby on Rails development environment in Windows? It’s really not as easy as people make it out to be. Sure, it’s easy enough to grab the installer and get ruby -v and irb to work from the command line. Still getting a decent working Rails development setup is tricky. Here’s all of my steps (accurate and working as of December 31, 2010).
- Downloading Ruby: You’re going to need a copy of Ruby, so go to rubyinstaller.org for that. Click the link that says “Downloads” and grab the latest version of 1.9.2.
-
Installing Ruby: Run the installation executable. Make sure that ruby binaries folder gets added to your path. My setup has Ruby installing to C:\Ruby192\bin, but yours will depend on your setup. Check that everything is working by running the command line and typing
ruby -v. If all is well, you’ll seeruby 1.9.2p0 (2010-08-18) [i386-mingw32]. -
Set up your database: I recommend MySQL. I’ve got a working version of MySQL 5.5. Go download a copy of MySQL Community Server. No matter what type of OS you have, get the 32 bit version! The 64-bit version will run just fine, but the Ruby mysql2 gem will not. Run the installer. I took the extra step of removing any spaces from my installation path. Spaces just add a layer of frustration when dealing with the command line. I put mine at C:\MySQL for simplicity. Also, let’s be sure that your
\binand\includedirectories are in your path. -
Check your MySQL setup: We can make sure that everything is working by typing
mysql -V. If you installation is working, you’ll seemysql Ver 14.14 Distrib 5.5.8, for Win32 (x86). We also need to make sure that the service is running, and that it’s on the default port (3306). Again, on the command line, typenetstat -ao | find "3306". If, for any reason, you put MySQL on a different port during installation, use that port number instead. When I do this, I seeTCP 0.0.0.0:3306 office-pc:0 LISTENING 33368. So port 3306 is open and listening. The Process ID (PID) is 33368. (Yours will be whatever your OS assigns.) I can check that 33368 is, in fact, MySQL by opening up Task Manager, selecting Services, and seeing that MySQL is running with PID 33368. Great! Let’s move on.
- Ruby editor: Let’s talk about editing Ruby files. Code coloring is a must. I’ve tried RubyMine from Jetbrains, and it is really, really good. It’s got really good code coloring and quite decent code completion. Since I am a .NET developer by trade, I really start thinking about having a very, very strong IDE. Ruby isn’t about that. It’s text. There’s no compiler. You need the best text editor you can find. For me, that’s been E Text Editor. Honestly, it’s just outstanding. 30 day trial and $47 for a license is not a waste at all. Plus, I use it for all sorts of XML and *.config documents. I even use it for MSBuild files. It’s a great text editor and totally worth the money.
- Theme and Font selection: I like the built-in Cobalt theme for E. Your milage may vary. For fonts, I’m using Monoco right now. It’s my new programming font. I like it so much that I’ve set that as my font for Visual Studio, as well.
- Empowering the console: The default Windows console, cmd.exe, is pretty weak. Go get yourself a copy of Console. It’s a SourceForge project, and it makes working with the command line much, much easier in Windows.
-
Gem install Rails:
gem install rails --no-ri --no-rdoc -
Gem install MySQL2:
gem install mysql2 --no-ri --no-rdoc. Check that it’s working by going to your command line.C:\> irb irb(main):001:0> require 'mysql2' => true irb(main):002:0> client = Mysql2::Client.new(:host => "localhost", :username => "root", :database => "your_database_name") => #<Mysql2::Client:0x2a17dd8>
Great! We’re about to connect to MySQL with the mysql2 gem in the Ruby console.
That ought to do it. Enjoy your Rails experience!