In the first and second part of this series, we talked about some foundational concepts regarding Rails development, and walked through the process of installing Ruby on your Windows machine. Now we’re going to start getting into the meat of things and install the Rails framework itself.
Rails is pretty much a one-line install, all you need to do is type this into the command prompt:
gem install rails –include-dependencies
You’ll be greeted by a “gem update” message, followed by a sizeable list of other things that are being installed alongside Rails. Depending on your internet connection, this process may take some time, so let’s use this opportunity to familiarize ourselves a bit more with the Windows Command Prompt, which you will be using a lot over the course of this article.
=============
The Command Prompt is a fairly janky piece of software from circa 1995, and although you will grow to hate it passionately over the course of your Rails career, you’ll have to accept the fact that it is simply a necessary evil. If you’re not overly familiar with the relevant syntax and concepts, you may want to check out this short tutorial on the subject before going on to the rest of this article.
One time-saving technique I can share with you on the subject (which for some reason isn’t covered in the tutorial I linked up above) is the use of the Tab key. It’s usually pretty hard to remember all the names of the various folders and sub-folders that you’ll be traversing and the quickest way to travel is to use the auto-completion feature via Tab. For example, let’s say you’re currently in your main user folder, like so:
C:\Documents & Settings\luis\>
You want to switch to the sub-folder “websites,” so you type:
C:\Documents & Settings\luis\> cd w
If there are no other folders in \luis\ that start with the letter “w” you can just hit the Tab key and the rest of the folder name will be filled in for you.
C:\Documents & Settings\luis\> cd websites
If there are other folders that start with a given letter, you can press Tab multiple times to cycle through all of them, and just press Enter once you’ve hit the one you want.
=============
Ok, so your Rails gem should be properly installed by now, and we’ll confirm that by typing “rails -v” into our command prompt. It should return something like this:
Rails 1.2.2
Congratulations, you’ve got Ruby on Rails!
Now, I know you must be getting pretty excited, but we’re going to have to take one brief sidetrip before we can start hacking together our first Rails application. We’ve got our interpreter and our framework, but so far we don’t have a way to store any data yet, which is a problem that we’ll remedy now.
MySQL is a pretty easy app to install, fortunately. Just make sure all the Client Programs are available so you can easily administrate your databases through the command line. As the very last step of installation process, you will be asked if you want to “Configure the MySQL Service Now,” which you should. When the dialog box appears, choose Detailed Configuration, then select Developer Machine. On the database usage dialog, choose Multifunctional Database. The next dialog will ask you if you want to change the path for InnoDB databases, which you don’t. Just click NEXT on that one. Click NEXT on the “concurrent connections” step as well. On the Networking Options dialog, make sure that both Enable TCP/IP Networking and Enable Strict Mode are both checked. Click NEXT on the proceeding Language dialog.
In the Windows Options dialog, check all three boxes: Install As Windows Service, Launch the MySQL Server automatically, and Include Bin Directory in Windows PATH. In the Security Options slide, you will be asked for a new root password. I recommend unchecking Modify Security Settings and just leaving your database unprotected. The reason for this is that this is just a developer machine and it’s an added hassle if you have to type in your password every time you want to manage your databases (which is going to be pretty often). Finally press EXECUTE to commit all your changes.
Now, to test if that all worked, we’re going to try to access MySQL from the command prompt. To do so, we type:
mysql -u root
This command calls the mysql executable, and the -u switch tells it that you are logging on as the root user. Because you did not specify a password for the root user in the configuration steps, mysql should load up immediately.
If you instead got an error message that MySQL was “not recognized as an internal or external command” then you’ve hit the same problem we had with Ruby in the previous article. Again, all you have to do is go to My Computer -> Properties -> Advanced -> Environment Variables, then edit the Path value. You will need to add the path to MySQL’s bin folder into that list (by default, it should be C:\Program Files\MySQL\MySQL Server 5.0\bin).
To leave the mysql console, type exit.
What you want to do know is install the Ruby gem for MySQL, which we do by typing:
gem install mysql
You will be confronted with a list of 5 or 6 options, which you will select by typing the number corresponding to your choice. At the time of this writing, the correct choice was #1 (mysql 2.7.3 mswin32), but generally what you want to do is choose the newest version for your specific operating system. Type “1″ and press Enter.
Ok, so now we’ve got Ruby, Rails, MySQL and the MySQL RubyGem all successfully installed. What’s left on our list? Well, as it happens, we’ve only got two more steps left, i.e., installing RMagick (our image-handling plugin) and subversion (our version-control system).
Quick links to other articles in this series:
PART ONE: Introduction to Ruby, Rails, MySQL and Subversion.
PART TWO: Ruby Installation and Language Primer.
PART THREE: Rails, MySQL and the Windows Command Prompt.
PART FOUR: RMagick and Subversion.