Installing REE and Passenger under Mac OS X Snow Leopard
I've been writing a Ruby On Rails application on my Mac for a little while. But as I moved forward I got tired of running Mongrel using ./script/server since it did not allow to test any SSL connections and it was a setup too far from my production environment. So I've decided to move from the standard ruby to ruby enterprise edition (ree) and work with Apache and Passenger on my development machine.
The following are the steps and commands I ran to get this setup. It was on a computer running Mac OS X 10.6.2 (Snow Leopard)
Note: If you decide to follow these steps, make sure you have the Mac OS X developer tools (XCode, gcc, etc.) installed.
1. Backing up installed gem list
Gems installed in the default ruby need to be re-installed in ruby enterprise edition. The first step is to get the list of installed gem so they can be re-installed later. Login to the computer as an administrator and open a terminal. Then execute
sudo gem list | cut -d" " -f1 > ~/gem_list.txt
2. Removing previously installed gem
Removing the existing gems helps ensure that when the switch to ruby enterprise edition is completed there's no vestige of the old system ruby gem. It'll make it easier to detect if ree is replaced by the Mac OS X ruby version during an update.
Note: It does remove gems that were installed by default with Mac OS X, so from this point forward you are modifying your system. Removing gems could cause software that depends on them to stop working. However, I haven't yet seen any Mac OS software that needs any of the default ruby gems so I'd say it's safe enough to do so.
So, first make a copy of the list of modules that was made previously.
cp ~/gem_list.txt ~/gem_list-original.txt
Then uninstall all the gems by running
cat ~/gem_list.txt | xargs sudo gem uninstall -aIx
During the execution you'll get the following error message (in this example it's for actionwebservice but any gems would have the same solution)
ERROR: While executing gem ... (Gem::InstallError) cannot uninstall, check `gem list -d actionwebservice`
Since Mac OS X has more than one gem path, it means that this gem was installed in a folder that is not the default gem folder. To overcome this run gem list -d to get its location as in the following example.
sudo gem list -d actionwebservice
you'll get the something like this:
*** LOCAL GEMS *** actionwebservice (1.2.6) Author: Leon Breedt Rubyforge: http://rubyforge.org/projects/aws Homepage: http://www.rubyonrails.org Installed at: /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 Web service support for Action Pack.
With the location in hand remove the gem as in this example. Make sure the command is on a single line when you execute it.
sudo gem uninstall -aIx -i /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8 actionwebservice
Finally regenerate the list of remaining gems using the command from step 1 and then repeat step 2 until all gems are removed.
sudo gem list | cut -d" " -f1 > ~/gem_list.txt
cat ~/gem_list.txt | xargs sudo gem uninstall -aIx
Note: If you are having trouble removing the acts_as_ferret gem, you need to create the /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/bin folder. Simply execute, and make sure the command is on a single line when you execute it:
sudo mkdir /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/bin
First get Ruby Enterprise Edition source files and extract them. The latest version is your best choice.
tar -xzf ./ruby-enterprise-1.8.7-2010.01.tar.gz
Run the installer.
sudo ./ruby-enterprise-1.8.7-2010.01/installer
When prompted for the path use /opt/ruby-enterprise instead of the default value. It'll make upgrading easier since you can just install over the older version. You'll also get a warning that it was unable to install mysql and pg. The reason for that is that neither MySQL nor PostgreSQL are installed on the Mac. It's not a concern if you do not plan to use either in the development environment. If you do, Install MySQL or PostgreSQL and run the commands the installer suggested.
Once ree is installed, the next step is to install Passenger in apache (the passenger gem gets installed by the ree installer). To do so, run
sudo /opt/ruby-enterprise/bin/passenger-install-apache2-module
With passenger installed. The final step is to setup Apache to use it. The passenger installer indicated a couple of lines to add to the httpd.conf it looked like this:
Please edit your Apache configuration file, and add these lines: LoadModule passenger_module /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.9/ext/apache2/mod_passenger.so PassengerRoot /opt/ruby-enterprise/lib/ruby/gems/1.8/gems/passenger-2.2.9 PassengerRuby /opt/ruby-enterprise/bin/ruby After you restart Apache, you are ready to deploy any number of Ruby on Rails applications on Apache, without any further Ruby on Rails-specific configuration! Press ENTER to continue.
So, first backup httpd.conf
sudo cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf.back
then edit the /etc/apache2/httpd.conf to add the lines the passenger installer wants to see added. I use emacs to do so:
sudo emacs /etc/apache/httpd.conf
Scroll down to the last line of the file using the arrow keys and paste in the three lines given by the installer (to paste go to Edit menu in the Terminal). To save the file hit CTRL+X and CTRL+S then to quit CTRL+X and CTRL+C
Replacing the ruby, gem and irb commands with their equivalent from ruby enterprise edition will make installing gems a lot easier. First make a backup of the current files
sudo mv /usr/bin/ruby /usr/bin/ruby.origin
sudo mv /usr/bin/irb /usr/bin/irb.origin
sudo mv /usr/bin/gem /usr/bin/gem.origin
Note: If for some reason you did not remove the gems that were previously installed, make sure you do the same for at least the rake command.
Next, make a link from Ruby Enterprise Edition to /usr/bin
sudo ln -s /opt/ruby-enterprise/bin/ruby /usr/bin/ruby
sudo ln -s /opt/ruby-enterprise/bin/irb /usr/bin/irb
sudo ln -s /opt/ruby-enterprise/bin/gem /usr/bin/gem
finally, adding /opt/ruby-enterprise/bin to the PATH will allow the other commands that are installed with gems to be available in the terminal (like the rake command for example). To do so we edit the .bash_profile path
emacs ~/.bash_profile
As the first line (if there is anything in there) add the following:
export PATH=/opt/ruby-enterprise/bin/:$PATH
Then save by hitting CTRL+X and CTRL+S then quit with CTRL+X and CTRL+C
Note: If you have more than one user that uses ruby on the computer you'll need to edit ~/.bash_profile for all those users.
Finally, update your shell with the new path. Execute the command:
source ~/.bash_profile
5. Installing gem
To re-install all the gems that were previously installed on the computer run
cat ~/gem_list-original.txt | xargs sudo gem install
It'll take a while to restore all the installed gems
6. Setting up Passengen Preference Pane
Last but not least, installing the Passenger Preference Pane. It'll allow to setup Rails project in Apache from the comfort of the Mac OS X PReferences.
First download the Preference Pane from fingertips. Extract the zip file and double-click on the Passenger.pre Pane file
System Preferences will open and ask if Passenger should be installed only for this user of for all users. I recommend going with all users.
And there you have it. Passenger Preference Pane is installed and working. All that's left to do is add you Rails project and enjoy your new setup.
7. And one more thing...
You might have noticed that in your Macintosh HD there's a new /opt folder. To hide it, run
sudo chflags hidden /opt








