Installing Ruby on Rails (RoR) with RadRails on Fedora 6
Sunday, February 18th, 2007
Categorized as: Ruby on Rails
For the last few weeks I've been learning Ruby on Rails. While it's not necessary to switch to Linux to develop in Ruby, I decided this was a good time to make the switch. I added a second hard drive to my PC for Linux (and I should have written that up, as well - whoops).
So far I've done a lot of reading on Ruby and Rails. Getting a computer set up to program with it, however, is a challange. All the books include instructions for Windows and Mac installations, but for Linux things get dicy. There are lots of versions of Linux, lots of instructions for how to install things, lots of web pages found by Google searches with people asking questions about the exact same error messages you're getting but rarely any decent answers to their questions.
Installing Fedora 6
To install Fedora 6 you need to download the install files, which you can burn onto one DVD or 5 CDs. The CDs are .iso images,which Windows computers don't burn to CDs naturally. You need to Google for a program that will burn an .iso image for you.
The next problem you need to solve is how do you get your computer to boot from the CD rather than from the Windows hard drive. This typically involves pressing a function key while your computer boots up. If you're lucky it will tell you what key to press on your screen.
In my case I had to hit f2, which brought up the BIOS screen. I used the arrow keys to go to the part about bootup devices and checked the CD and unchecked the hard drive. I had to reverse the selections to go back to booting from the hard drive. When you save the new settings and exit, the boot continues using the device you've just selected.
The official Fedora 6 installation guide is the resource I recommend for the Fedora installation. It's quite helpful as long as you don't run into any problems.
The first try at installing Fedora
The installation guide describes an http installation method, which lets the system download the material it needs from CDs 2 through 5. This made great sense to me, since it takes some time to download each CD. So for this first try I only downloaded the .iso image for the first CD.
The docs fail to mention that using the http installation method, you're left looking at a black screen with a big white, X-shaped mouse cursor, not sure if anything is happening or not, for half an hour or more. But the Fedora install screen eventually appeared and I was able to enter all the install information.
But then the install itself failed because my boot CD, which I had neglected to verify, had parts that were unreadable. At that point I remembered that I had never successfully burned a working DVD or CD from the drive in my Windows machine, and I moved the image over to my Mac loptop, which has built-in support for burning .iso images to CDs.
The second try at installing Fedora
Spooked by the long sitting with the black screen, I decided to download the other four CDs, but rather than actually burn them I'd use the hard drive installation method.
As it happens, I have an external USB hard drive attached to this machine. It uses the Windows fat file system, which Linux can read. If it had been formatted with Windows' ntfs file system, on the other hand, I would have been out of luck. I downloaded the other four .iso images to a folder on this drive, which took a bit of time, but at least I could tell the downloads were progressing instead of staring at a black screen.
I flew through this installion, accepting all the defaults. When the installation was finished I reverted the BIOS to boot from the hard drive. But the computer stopped mid-boot with a message on the screen about Grub having ERROR 15, which the internet told me means file not found. I couldn't get into either Windows or Linux!
After a couple of frustrating hours trying to figure out what the error meant and how to fix it by reading Grub documentation, I had the bright idea to just do the installation over. There's a particular part of the install that I think caused my boot problem - it's where you set up the partitions on your disk.
The third try at installing Fedora
When you're going through the installation screens, one of them has to do with how to partition your hard drives for Linux. As I mentioned earlier, in addition to the Windows hard drive and the USB hard drive, I had added a second internal hard drive to this computer for Linux. As it happened, the easiest way to do that in my case was to use an empty second connector on the cable that was plugged into my CD/DVD drive. The computer's first hard drive plugged into a different cable that didn't have an empty connector.
This meant that from Linux's point of view, my Windows hard drive was hda - a indicating the first drive on the first cable. There was no hdb (second drive on the first cable), the CD was hdc (first drive on the second cable), but not really a hard drive, so it didn't show up either. The new drive was hdd (second drive on the second cable) and the USB drive was sda.
During the previous installations I had told Fedora to use hdd for the Linux drive, but I had accepted its suggestions for how to partition the drive. It chose to use LVM (Logical Volume Management) partitions, which is the most advanced method. I have a strong suspicion that this is why Grub couldn't find the files it was looking for.
This time I set the partitions up manually. I left the suggested /boot partition in place, added a /swap partition twice as big as the amount of memory the PC has, made a 20 meg / partion and let the rest of the drive be a /home partition. The / and /home partitions I formatted as ext3.
And this time the computer booted just fine. Grub's bootup menu lets me select whether I want to boot into Fedora or Windows and works as expected. Of course that's no big deal, unless you've been through the frustration of it not working as expected.
Installing MySQL
Getting the MySQL software onto your computer seems easy enough with Fedora. You just use the yum installer (or the equivalent apt-get if you have a version of Linux in the Debian family).
But what you do next isn't clear. How do you start it? How do you configure it? How do you get it to automatically start when you turn on your computer? Why does Rails insist on a /temp/mysql.sock file and why is it missing?
After an inordinate amount of messing with this, I finally found the magic Google search term that lead to some excellent documentation on Installing and configuring MySQL server on Fedora 6.
Read that document first, but basically the process is: log on using your root account, open a terminal window, and type yum install mysql mysql-server. Answer Yes to the Is this ok? questions.
Next, enter service mysqld start. This initializes MySQL. At this point it has one user, root, whose password is blank. The installation document then has a section about setting up other accounts with passwords, but Ruby on Rails developers seem to typically ignore this on their personal development machines.
The next critical step is to enter yum install mysql-administrator in your terminal. This downloads MySQL administration software with a Mac/Windows type interface. This is going to get us out of this terminal window!
But before we go, enter chkconfig mysqld on && service mysqld restart && chkconfig –list | grep mysqld, which will cause MySQL to start up automatically from now on. Now enter mysql-administrator and we're done with the teminal window as far as MySQL is concerned.
In the initial MySQL Adminstrator screen you have to log on to MySQL. The Stored Connection will be blank the first time you start it up. For Server Hostname enter localhost. For Username enter root. Leave Password blank unless you set up a password, in which case you need to enter it.
By entering a domain instead of localhost, you can connect to MySQL installations on remote machines. If you're going to be a Rails geek with no root password, at least keep people from connecting to MySQL on your machine. Select Startup parameters, then go into the sections for both mysqld and mysqld_safe and check the Disable networking box.
You can configure everything about MySQL using this program, however, there's nothing obvious about how to create a new database. The trick is to select Catalogs, at the bottom of the choices on the left. A Schemata area will appear at the lower-left; right-click on it. The Create Schema selection in the pop-up menu that appears is what you use to create the Rails _production, _development, and _test databases for your project.
Installing Ruby and Rails
Just as you'd expect from Ruby, its installation is the easist. But we do have to go back to the terminal window. We'll use yum to download Ruby and Ruby's version of yum, which is called RubyGems. Then we'll use RubyGems to download Rails. You can also get Rails with yum, but the internet is full of stories about how it's best to do it with RubyGems.
So, in your terminal, it's yum install ruby rubygems (note the word ruby appears twice in that command).
When that's complete, enter gem install rails –include-dependencies. There are two hyphens in front of the dependencies part, which is critical, as this tells RubyGems to get you all the other Ruby libraries that Rails needs.
Installing Eclipse and RadRails
We need to take one final trip to the terminal window to get software for writing Ruby on Rails software using a Mac/Windows style graphic environment rather than constantly typing commands in the terminal window. We're going to get a developer's package called Eclipse and a plug-in for it called RadRails.
In your terminal window, it's yum install eclipse-pde-devel (yes, by now I also would have thought it would be yum install eclipse, but that's just one more frustrating dead end).
If you've been following along, at this point you're still logged into your computer using your root account. It's time to log out of that one and log back in using the account you created the first time you started up Fedora.
From within this account start another Terminal window and type eclipse. This will start the Eclipse software. It's a big package and takes a bit of time to start up. First it will ask you for the name of a workspace you want to use. This is where all your programming files will go. Accept the suggested name for this directory, or change it to something you like better.
I found out how to install RadRails into Eclipse from an article on Stoneageblog, which is written in French. I barely read French, but the article included enough screenshots that it's easy to figure out what you need to do.
In Eclipse, click on the Help menu and select Software updates/Find and Install…. On the next page, change the radio button selection to Search for new features to install and click the Next button.
On the next screen we have to add two new remote sites. So click the New Remote Site button. For the first one, enter RDT for Name and http://updatesite.rubypeople.org/release for the URL. For the second site, enter RadRails for Name and http://radrails.sourceforge.net/update for the URL.
When you have the two new sites added, they should be checked. Click the Finish button. On the next page, select the two packages again and install them. When installation is complete, Eclipse will ask you to let it restart.
When it restarts, open the Window menu and select Open Perspective/Other…. In the menu that appears, pick Rails. If nothing seems to happen, close the uppermost Eclipse window.
Now we need to configure RadRails. Open the Window menu in Eclipse and select Preferences. In the list on the left, click the triangle in front of Ruby. Select Installed interpreters and click the Add button. The location to add will be something like /usr/bin/ruby, although there will be a version number after ruby. (If it's not there, try /usr/local/bin/ruby.)
Now pick Ruby's Ri/rdoc selection. The path to these two programs should be the same as the path to Ruby.
Now expand the Rails item and select Configuration. Again, you should be able to find Rails and Rake in the same place you found Ruby. Mongrel, on the other hand, will be somewhere like /usr/lib/ruby/gems/1.8/gems/rails-1.2.2/lib/ commands/servers/mongrel.rb. The numbers may have changed by the time you read this.
That's it, everything you need is finally installed. There are RadRails tutorials on the RadRails site. Ruby on Rails for Dummies also has a good introduction to RadRails. To start your first Rails project, click in the area on the left and select New/Rails Project….
Setting up start buttons
Fedora lets you add your own buttons to the menu bar at the top of the screen for starting programs. Right click on the menu bar, select Add to panel, in the window that appears select Custom application launcher, and click the Add button.
Click the No Icon button to select a suitable icon for your start button and name it. Now, in the Command box, we just have to put the path the program. To make a button for Eclipse, look for it in /usr/bin or /usr/local/bin.
