Setting Up Your Development Environment
Welcome to the eighth lesson of Learning Rails, the free online course that will get you started with Ruby on Rails. I’m Michael Slater.
And I’m Christopher Haupt.
In this lesson, we’re going to explore your options for setting up your development environment. The next lesson begins our screencast series, in which we’ll build a complete Ruby on Rails application, step-by-step. If you have your development environment set up, you’ll be able to follow along.
Like the earlier episodes in this first series of Learning Rails podcasts, we’ll stay at a mostly conceptual level. See the Lesson Page for links to detailed tutorials on setting up your development tools. And while you’re there, sign up for our screencast mailing. You’ll get an email notification of each screencast as it is published, along with links to the sample code.
On each Lesson Page, you can now post comments. So if you have questions after listening to this lesson, please post them there.
Choosing Your Platform
Selecting an operating system is kind of like looking at a piece of artwork. Beauty (and functionality) is in the eye of the beholder. In some cases, you don’t even get to choose; the choice is made for you by your circumstances. And in many cases, while you may have had a free choice at some point in the past, you now have an investment in hardware and software that makes it painful to change platforms.
We’re going to focus primarily on the two most popular operating systems in use in the Ruby on Rails community for development machines: Apple’s Mac OS X and Microsoft’s Windows.
While we won’t give specific attention to Linux, Solaris, or other Unix-like operating systems as development platforms, everything we do can be done on those platforms as well. Some details will differ, but with the exception of OS-specific installation details, you should be able to follow along without much trouble even if you’re running one of the “*nix” operating systems for your desktop environment.
It is a very common scenario is to develop under Windows or Mac, and then deploy to a different operating system for production use on a separate server. We’ll cover mixed operating system scenarios when we talk about deployment and operations considerations later in the course.
Windows Advantages
For most Ruby on Rails developers using Windows for their development environment, the overwhelming reason for their choice of operating system is that it’s what they already have. In the business world, using Windows is the path of least resistance, and many businesses run almost entirely on Windows. Windows systems are generally less expensive than comparable Macs, and there is a wider range of software available.
Windows is certainly usable as a Ruby on Rails development platform. For the most part, though, it has few advantages in itself; it is more a question of minimizing any disadvantages while making use of the hardware and software you have available.
Macintosh Advantages
If your have the luxury of choosing either Windows or Mac for your Rails development work, Mac has a lot going for it, even putting aside any differences in the quality of the hardware or the overall user experience:
- Because Mac OS X is a Unix-derived operating system at its core, many development tools (such as native C compilers that are highly compatible) are more readily available, free, and easy to use. This is less true on Windows. A common challenge comes up when developing under Windows when Ruby components that require native libraries don’t come with prebuilt libraries or libraries that use an uncommon run-time. Such components just won’t work, or will require a lot of work on your part to hunt down (or buy) compilers or other development tools.
Again because it is Unix underneath, you can apply all of the scripting and administration techniques you learn for use on your production server to your development system as well. Having this commonality across development and server environments reduces pain and schizophrenia.
Since you can use Parallels or VMWare Fusion to run Windows on your Mac very smoothly, but you can’t practically run the Mac OS on a Windows system, the Mac is a more complete solution. You can, for example, keep Windows XP and Windows Vista partitions with various versions of IE and other Windows browsers for testing.
Because most experienced Rails developers are using Macs, the blog posts and tutorials are most often written based on Mac-only experience, and you can run into stumbling blocks if you’re using Windows.
- TextMate, a Mac-only programmer’s editor, is very widely used in the Rails community. It is an excellent editor, and the one for which you’ll find the most Rails- and Ruby-specific add-ons.
In the end, it is up to you, of course. We prefer Macs, but we’ve done lots of Rails work with Windows as well, and it is certainly doable. In our daily work, we use Mac OS X Leopard, Linux (various distros), Solaris, and even Windows from time to time.
The Common Components
Regardless of the operating system you are using, the kinds of tools you will be using in your development environment are identical. You will need Ruby, Rake, the Gem package manager, the command line version of the Subversion source code control system, the MySQL database server and command line tools, a programmer’s code editor, a command line SSH program, and a variety of gems, including, of course, Ruby on Rails.
On all platforms, you’ll be using your operating system’s command-line interface. You’ll need a passing knowledge of basic shell commands, such as moving around in directories, listing files, creating new directories, and invoking programs.
While the tool set is pretty generic, there are differences to setting up these programs on different operating systems and there are minor differences using the programs as well. We will spell out differences as we go.
Michael: Mac OS X 10.5 (Leopard) Setup
Apple’s Mac OS X Leopard (aka 10.5), is perhaps the easiest desktop operating system to get going for Ruby on Rails development. Apple preloads many of the tools you will be using and it is relatively easy to get the rest installed. Let’s walk through the steps in general. Refer to the articles listed on the Lesson Page for detailed step-by-step instructions.
The first important step is to make sure the Mac’s native development environment, Xcode, is installed. Xcode includes C, C++, and Objective-C compilers as well as other handy development tools. You sometimes need a C compiler when you install Ruby code that contains native-code library components. The Gem tool will automatically build native libraries for you, so you just need to make sure the compilers are installed.
Apple provides the two software installers you will need for this step on your original Leopard installation DVD. You can also download them for free from Apple’s web site. Look for and install the X11 and Xcode packages to get all of the tools you’ll need.
To make installation of other software tools simpler, we like to use the MacPorts package manager. MacPorts (or “ports” for short) is a system similar to Ruby’s Gem package manager, but instead is used to install native software programs. Ports is handy because it takes care of all of the work of downloading and installing selected packages. It gets the software plus any dependencies, compiles the code, and installs the software in the correct place on your system. Ports even handles easy updating of packages and, when necessary, deinstallation too.
After installing MacPorts, you need to update your command line shell’s path information so Ports commands can be found. Edit your shell profile file, which by default on Leopard is the file .bash_profile in your home directory. Within the .bash_profile file, append the path to MacPorts-installed software to your PATH environment variable. The default MacPort paths are /opt/local/bin and /opt/local/sbin. Once you have the paths set, open a new terminal window and tell MacPorts to update itself (sudo port selfupdate). You are now ready to load software via MacPorts.
MacPorts has thousands of community-contributed packages. In this lesson, we are using Ports to install the MySQL database system.
(Note: if you want to minimize the installation work, you can use the sqlite3 database that is the default for Rails 2 instead. It isn’t a database you’d use in production, however, and we prefer to run the same database in both development and production environments.)
The detailed installation notes in the articles listed on the Lesson Page provide the specific commands, so we will just highlight what the steps do here. First, you install the MySQL programs which include command line tools and the actual database server. Next you configure the database software so it automatically starts up for you. You then initialize a new database storage area, fire up the server for the first time, and set up some account information.
You are on the home stretch and are ready to get the Ruby on Rails environment updated for our use. Fortunately, the Gem tool does most of the work for you. Just issue the gem update command and watch as Rails and all of its parts get updated to the latest release.
One thing to note: when you use commands like “gem” or “port”, you typically need to do so with a higher level of permission than your account typically has. The reason for this is that the operating system stores these programs in areas that are owned by the system itself. On Mac OS X and other Linux or Unix operating systems, you temporarily enable higher levels of permission using the “sudo” command. To use sudo, simple type it immediately before the command that needs permission. In the case of the gem update you are trying to do here, type in the command “sudo gem update”.
One gem in particular needs special attention. The Ruby adapter for MySQL is a little tricky to install; depending on whether you are on a newer Intel-based processor Mac or an older PowerPC based Mac, the command is different. Please refer to the articles listed on the Lesson Page for the full details.
With that, you have a baseline installation for exploring Ruby on Rails. There are some optional software tools you can set up next, but first, let’s discuss getting to this same baseline point on Mac OS X 10.4 (Tiger)
Mac OS X 10.4 (Tiger) Setup
Unlike Leopard, Mac OS X Tiger doesn’t have recent versions of the key software packages you will need for exploring Ruby on Rails. If you’re planning to upgrade to Leopard, you might want to go ahead and do that first so you can use the simpler setup.
But if you want to proceed with Tiger, it’s not a problem — there’s just some additional software you’ll need to install.
First, like Leopard, you will need the native Mac OS X development tools installed. Install the X11 and Xcode packages as previously described. Install them from your Tiger DVD, or check Apple’s web site for the Tiger versions of the X11 and Xcode installers.
Next, install MacPorts just as we described earlier in this lesson. In the case of Tiger, you are going to use more of the Ports collection of packages to construct a full Ruby and Rails development environment. After you have MacPorts command paths set up and MacPorts is self updated, you’ll issue a series of ports commands to install Ruby, Gems, and Subversion. See the articles listed on the Lesson Page for the specific commands.
Follow the same process described for Leopard in the previous section for installing MySQL using Ports.
Since Tiger doesn’t have any of the gems you are going to need, you can install all of the baseline gems in one swoop. This includes Rails, Rake, Capistrano, Mongrel, and Mongrel Cluster. (These gems will also, by default, install all of the gems they depend upon.) One the installation completes, install the MySQL adapter as we described for Leopard.
With the gems installed, you have a baseline Ruby on Rails development environment ready to go.
Supplemental Mac Programs
We mentioned earlier in this podcast that we will use some other programs as part of our standard development environment. In particular, we will use a programmer’s editor, the command line and SSH compatible terminal programs, and perhaps some other convenience programs. At LearningRails.com, we use iTerm as our terminal program, Mac OS X’s built in SSH implementation (based on OpenSSH), the commercial text editor TextMate, and the open-source NetBeans programming environment from Sun.
To make working with the MySQL database a tad bit easier, the donationware CocoaMySQL program provides a simple GUI front-end, and the commercial Navicat product is a more capable, cross-platform alternative.
Windows Setup
Getting a Ruby on Rails development environment working on Microsoft Windows requires a similar number of steps as setting up Mac OS X. Unlike the Mac, it is less common for Windows users to have access to a native C compiler. The Ruby community has worked around this problem by supplying prebuilt versions of many libraries within Ruby gems.
Unfortunately, with the many changes to Windows XP and Windows Vista over time, sometimes these binary versions can be a little problematic. We’ll set up a fairly plain development environment to meet our needs for this course. You may want to do some exploring of the links we provide at BuildingWebApps.com and elsewhere on the net if you run in to issues as you grow your environment.
The good news is that you can get pretty far in setting up the baseline Ruby environment with the “One-Click Ruby” installer, available on RubyForge. The One-Click Ruby installer sets up Ruby, Ruby Gems Package Manager, Rake, all of the other standard Ruby tools, and even the open source SciTE programmer’s editor for you. Additionally, the installer configures the command line interface path information, so the Ruby tools are ready to use in the Command Prompt program (Start > Run … > cmd).
(There’s another widely used shortcut setup for Windows, called Instant Rails. It’s the simplest way to set up your development environment, but it has some limitations and oddities, so we’ve chosen not to use it here.)
Once Ruby is installed, you need to set up MySQL. Here, you’ll want to install the official Windows Essentials installer package from MySQL.com. Download the installer and let it run using the “typical” options setting.
The installer will unpack the MySQL database server, the MySQL command line tools, and all supporting files needed to build a database. After the installer completes, it offers to configure the database settings. You should go ahead and do this, selecting the option to provide detailed configuration options. As you are setting up a development environment, select the Developer Machine option so MySQL consumes the least resources on your computer. You can accept all of the default settings, although we recommend the simplicity of selecting the “Include Bin Directory in Windows PATH” option when presented. If you don’t select this option, you will need to manually set up your path so the “Command Prompt” program has easy access to MySQL client programs.
You will also be presented with a dialog to set a root password. If you are going to be working locally and aren’t worried about security, you can deselect “Modify Security Settings” and have a blank root password. We suggest you set a password, though, “just in case”.
You are going to need a command line tool to interact with your source code control system. We use Subversion. Installation is very simple. Just grab the installer from subversion.tigris.org for the latest basic Subversion Windows client and let it run. The installer will automatically set up your command prompt path for you.
You are also going to need an SSH compatible terminal program when it comes time to deploy and log in to your web servers. We recommend the PuTTY SSH client. See the articles listed on the Lesson Page for links to the installer. The installation program will automatically set the application up for you.
You are now ready to finish up our baseline development environment by adding the critical remaining gems that we’ll need, including, of course, Ruby on Rails. From your command prompt, run the gem install commands for rails, Capistrano, Mongrel, and Mongrel Cluster. Fortunately, setting up the MySQL gem is a lot easier on Windows; you simply type “gem install mysql”.
Supplemental Windows Programs
The One Click Ruby installer provides the capable SciTE programmer’s text editor, which may be adequate for your needs. However, there are many other opensource and commercial programmer’s editors, such as jEdit and SlickEdit, respectively. If you would like to use an integrated development environment, we recommend Sun’s opensource NetBeans IDE on Windows too. Note that when you install NetBeans on Windows, you will need to also install a copy of the Java Runtime environment (or full development environment). The Netbeans installer on Windows should walk you through that extra bit.
Under Windows, Netbeans has an acceptable GUI for databases, but you might want to explore a dedicated product such as Navicat or SQLyog to make working with MySQL a little easier. Another handy GUI tool is the TortoiseSVN Subversion Shell Extension. This tool integrates Subversion access with your File Explorer windows, making it easier to do simple Subversion commands without having to use the command line. For our tutorials, we’ll be using the command line in most cases, but you should check out Tortoise too.
Conclusion
In our next episode, we’re going to switch to a video format, showing you our computer screen as we build a Ruby on Rails application, step by step. If you have your development environment set up, you’ll be able to follow along with us. Don’t forget to sign up to get notified when screencasts are available and to get pointers to our sample code.
Comments on This Lesson
From: cherrian Date: 10/16/08 01:13 PM
Subject: ruby 186-26.exe
Ruby 186-26.exe does not respond to the check command.
Also, I am not able to give the command install rails, capistrano mongrel mongrel_cluster
What do you suggest?
From: cherrian chin harada Date: 10/16/08 04:04 AM
Subject: Setting up my environment
Hi, I hope you can help me on this matter. I working on a windows XP and I am following your lesson details but I am not sure if I am now at the stage to move to lesson #9.
I click on the one-click Ruby installer and then I in Ruby Forge page, I then click on download but no indication or confirmation. I did not get any Ruby 186.76 set-up box from wizard…I did not see it running on my PC. Each I go to download I have this same experience, can you tell me why?
From: cherrian chin harada Date: 10/11/08 08:08 AM
Subject:
I have problem hearing the recording on lesson #8
From: cherrian chin harada Date: 10/11/08 08:08 AM
Subject:
I have problem hearing the recording on lesson #8
From: Peter Date: 09/04/08 11:23 PM
Subject: Instant Rails
You have a rather oblique criticism of Instant Rails. After looking at some extremely long and tortuous set up procedures (elsewhere) I installed it with relief and it works well. What’s the matter with it?
From: Christopher Haupt Date: 07/25/08 08:08 AM
Subject: MySQL Root Passwords
The thing to check first is to make sure you can get in to MySQL from the command line (in a DOS/Command Prompt Window, does mysql -p -u root work when you hit return at the password prompt?).
From: AussieDave Date: 07/10/08 10:22 PM
Subject: Ruby and My SQL root password
Hi am just starting lesson 9 and get an error
Access Denied for user ‘root’@’localhost ’ (using pasword NO) when I click on the about your applciation environment in tjhe wlecome abourf index page
I am running on windows XP
Thanks
Dave
From: Philipe Farias Date: 05/22/08 04:16 PM
Subject: Ubuntu instructions
Installation instructions for Ubuntu (7.10 or 8.04):
1. open terminal
2. paste this command sudo apt-get install ruby rubygems irb
3. wait the installation then paste sudo gedit /usr/bin/gem
4. after the line require 'rubygems' paste require 'rubygems/gem_runner', save and exit
5. back on terminal sudo gem update and sudo gem update --system
6. now sudo gem install rails
7. and if you want to boost gedit see this for beginning: http://github.com/mig/gedit-rails/tree/master
8. or simple sudo apt-get install vim-ruby vim-rails for vim editor
9. for mysql sudo apt-get install mysql-server (optional)
10. for postgresql sudo apt-get install postgresql-server (optional)
From: Christopher Haupt Date: 05/22/08 12:12 PM
Subject: RE: When you already have MySQL
No need to set up another instance of the DB. If you are already running successfully, just use the one you have. You can follow the rest of the instructions. The one thing you may need to tweak is if you have problems building the mysql gem (on Mac/Linux, you’ll likely use the binary version on Windows). On Mac/Linux, tweak the instructions so that the command paths are to your installation (where-ever it is) instead of the assumed “ports” version of /opt/local…”
From: Xavier Date: 05/22/08 11:11 AM
Subject: instruction when MySQL already installed using WAMP (XP) or MAMP (MAC)
I already had MySQL installed using WAMP (on XP PC) and MAMP on (OS X Leopard). Should I follow your instructions, and still install another MySQL Server, or bypass those instructions? I’m worried about either screwing up my ability to run Ruby on Rails, or PHP that was already installed.
From: Ramsesoriginal Date: 05/16/08 11:11 AM
Subject: Ubuntu - Linux in general
Hi.
In ubuntu its really easy: open a termianl and type
sudo apt-get install ruby rails
for a basic system.
From: Zeck Date: 05/11/08 03:03 AM
Subject: Install on Ubuntu
Hi,
How to install ruby on rails on ubuntu 8.04 ?
Any Idea ?
From: Grzegorz Date: 05/10/08 11:23 PM
Subject: upload file
How to upload file to server in Ruby? Help me !
From: K Goarany Date: 05/06/08 07:07 AM
Subject: Ubuntu Version
Thanks Chris! In our CS lab, we’re running 7.10 “Gusty Gibbon”.
From: Christopher Haupt Date: 05/05/08 05:17 PM
Subject: RE: RoR on Ubuntu
Thanks all for the requests for a write-up regarding Ubuntu. I’ll add it to the list for a future article. What version are folks running out there?
From: K Goarany Date: 05/05/08 02:14 PM
Subject: RoR on Unbutnu
Thanks Chris & Michael for your great podcast! I for one would love if you would do a write-up for setting up RoR in Ubuntu
From: K El-Goarany Date: 05/05/08 02:14 PM
Subject: RoR on Unbutnu
Thanks Chris & Michael for you great podcast!
I for one would love if you do a write-up for setting up RoR on Ubuntu.
From: hayat Date: 05/04/08 11:11 AM
Subject: Please
What about Detailed Ruby on Rails Development Environment Installation Instructions
on Ubuntu????????
From: Christopher Haupt Date: 04/30/08 09:21 PM
Subject: RE: Linux
So far we’ve been covering the majority case of current screencast downloaders for OSs. For most Linux distros, the simplest way to get started is to use the particular package management system available on your machine (rpm. yum, apt-get, etc.), pull down the Ruby and MySQL packages, and if needed, grab RubyGems and follow the readme for its install. Once you have that, the instructions for grabbing gems is pretty similar to the Mac OS instructions. If there are particular rough spots out there, we’d love to hear about them. If enough folks write in, we might do a representative write-up for something like Ubuntu.
From: pillar Date: 04/30/08 07:19 PM
Subject:
Linux?


From: Chris Cuellar Date: 10/29/08 05:05 AM
Subject: Ruby Script/Server?
Hello,
I installed rails and check to be sure all my files were working (they were)When I go into command prompt to start the server with ruby Script/server I get an error saying no such file. I am running vista. the other question I have is I downloaded “E” text editor what command do I use to start the test editor from command prompt on windows vista?
Thanks,
Chris