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 
3. Installing Ruby Enterprise Edition and Phusion Passenger

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

4. Replacing ruby commands with REE

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

Passengerpane

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.

Systempreferences

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.

Passengerprefpane

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

 

 

 

Filed under  //  development   macosx   rails   ruby  
Posted

Warm coffee and dreadful weather

I do not know what makes it so enjoyable; but, having a warm coffee while it's pouring rain outside just instantly makes me feel better.

Img_0087

Of course, knowing that I'll need to go  back out will make me think twice about finishing that coffee...

Filed under  //  photo  
Posted

Tweeting from the top of a mountain feels kinda weird.

Image

Can't argue about network coverage.

via tweetie

Filed under  //  hiking   photo  
Posted

The hard life of my cat

Img_0004

Snoring in my hears while we watch TV. I'm starting to beleive she's not interested in what's on TV.

Filed under  //  photo  
Posted

I finally understand the keyboard layout on an iPhone

After a week of having an iPhone I've finally figured out why I needed two keyboard layouts to be able to write in English and French.

 

When I fist got my iPhone I've setup the phone to have a US English keyboard layout and a Canadian French layout since I write in both languages. My initial though was that the US and Canadian French keyboard had different option, for example I did not expect the US English keyboard to have French accents. However, on the first day, I've figured out that I was wrong about this since both keyboards had exactly the same layout and options. I decided then to do away with switching keyboards and simply sticking with the US English keyboard. For the next few days I've started fighting the phone when ever I would write in French. It seemed that the iPhone would go out of its way to replace perfectly good French words with English ones. For example it would insist on placing capitals on some words or simply replacing the entire word with another English word. Writing in any other language than English became a struggle.

 

I started by cursing Apple for making the auto correction feature English only. But as much as I thought about it the less it made sense that they would make such a bad design choice. But this morning, as I was about to disable the whole auto correction feature, I had an idea. Maybe, just maybe, Apple did not really mean only Keyboard in their options and more something like "Keyboard and Dictionary" as the Blackberry does. So I went into Settings->General->International->Keyboards and added back the French Canadian keyboard. I then used the said keyboard layout to write an email in French and, to my great pleasure; the phone started correcting spelling error and typo correctly and effortlessly. It doubled my typing speed right away!

 

So, it may have taken me a week but I'm now back to the world of handling my email as they come in After almost a year without a smart phone I can now get back to Inbox Zero.

 

Filed under  //  iphone  
Posted

Where do I live?

If you read my bio you'll see that my home is located in Quebec city, Qc, Canada. However, when I talk with my neighbour I often end up with the feeling that I'm not from the same place as they are. We definitively do not watch the same TV shows, don't listen to the same movies and, most of the time, we do not even get the same news.

Contrary to my neighbours I do not get my news from the local radio station or from TV broadcast. I get my news from the the RSS feeds of Le Monde, CBC Canadian news feedReuters, etc. I get my in depth coverage of issues through podcasts like TVO the Agenda and Euromag. The tech news I need to stay current in my field I get from RSS feeds like Lifehacker, ARS Technica, TVO  Search Engine, CBC Spark, Ruby 5 and many others. I even download my entertainment on iTunes be it free podcasts like Laughing Out Loud or Stack Overflow podcast (admittedly a mix of tech and entertainment) or simply by buying directly the TV shows and movies I care about. For me the word local media does not really apply to anything any more. From my computer a lot of media becomes "local" media.

Also contrary to my neighbour, I do not need to find someone to give me the highlights of the news I've missed while I was away. If I can get access to a computer and the internet I can get all my news from anywhere and if I cannot go online then it'll wait for me to come back.

More and more we hear about that the future of medias is through "hyper-personalization" of the news. From where I stand I've already have that today. The real issue we have is the rate of adoption and accessibility. And to top that, how are we going to have casual conversation with family, friends and neighbours about local events if local events vary from one person to the next? 

Filed under  //  news  
Posted