Badminton on Rails
RSS icon Home icon
  • Setting up Ruby on Rails, MySQL, Mongrel, memcached, and RMagick using MacPorts on Mac OS X 10.5 Leopard

    Posted on November 29th, 2007 Raymond Law 8 comments

    I recently got the new Santa Rosa Macbook with Leopard pre-installed and I need to set up the Rails development environment.

    Basically there are 3 ways to achieve that:

    1. Locomotive

    Locomotive method is simple and self contained. It works very well for Mac OS X 10.4 Tiger. However, the author acknowledges that Locomotive may not be Leopard ready.

    2. Rails comes with Leopard

    That’s right. Apple has included Rails by default, as noted by DHH. This sounds great. However, that means you will also have to manually install Imagick, RMagick, and all those other stuff that you need for development. Also, it may be harder to upgrade Ruby or Rails when new versions come out. You probably need to install from source to upgrade or what not…

    3. MacPorts

    You might already have your Rails environment set up using MacPorts. If that’s the case, why not just use that? Even if you are like me with a fresh installed Leopard, MacPorts still has its advantages. For example, you can use MacPorts to upgrade ruby in the future.

    I used MacPorts to set up my Rails environment based on these other great articles:

    1. Install the latest Xcode version for Leopard. Download from the Apple website.

    2. Install the latest MacPorts version for Leopard. Download from the MacPorts website.

    Run this to update MacPorts:

    sudo port selfupdate

    3. Install Ruby, RubyGems, and Rails.

    sudo port install ruby
    sudo port install rb-rubygems
    sudo gem update --system
    sudo gem install rails -y

    4. Install MySQL (directly from Andrew Nesbitt, shown here for completeness).

    sudo port install mysql5 +server
    sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
    sudo -u mysql mysql_install_db5
    cd /opt/local ; sudo /opt/local/lib/mysql5/bin/mysqld_safe &
    sudo ln -s /opt/local/var/run/mysql5/mysqld.sock /tmp/mysql.sock

    5. Install mongrel and mongrel_cluster.

    sudo gem install mongrel
    sudo gem install mongrel_cluster

    6. Install memcached.

    sudo port install memcached
    sudo gem install memcache-client

    Create a file called /Library/LaunchDaemons/com.danga.memcached.plist, and insert the following:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
            <key>Label</key>
            <string>com.danga.memcached</string>
            <key>OnDemand</key>
            <false/>
            <key>ProgramArguments</key>
            <array>
                    <string>/opt/local/bin/memcached</string>
                    <string>-d</string>
                    <string>-m</string>
                    <string>64</string>
                    <string>-u</string>
                    <string>www</string>
                    <string>-p</string>
                    <string>11211</string>
            </array>
            <key>RunAtLoad</key>
            <true/>
    </dict>
    </plist>

    In order to launch memcached on boot, enter this in the terminal:

    sudo launchctl load -w /Library/LaunchDaemons/com.danga.memcached.plist

    7. Install ImageMagick and RMagick

    sudo port install ImageMagick
    sudo gem install rmagick

    NEW! There are now instructions on how to install ImageMagick and RMagick.

    8. Optional – I found out if you have the loaded_plugins gem installed, you may see the following error when running script/console:

    /opt/local/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:477:in `const_missing':NameError: uninitialized constant Gem::Version::NUM_RE

    The reason is MacPorts create two directories to store the RubyGems stuff in /opt/local/lib/ruby/site_ruby and /opt/local/lib/ruby/vendor_ruby. Ruby’s $LOAD_PATH looks in site_ruby first but the version.rb in site_ruby does not define Gem::Version::NUM_RE whereas the version.rb in vendor_ruby does. I’ve outlined the issue here. So I simply swap them:

    sudo mv /opt/local/lib/ruby/site_ruby /opt/local/lib/ruby/vendor_ruby_tmp
    sudo mv /opt/local/lib/ruby/vendor_ruby /opt/local/lib/ruby/site_ruby
    sudo mv /opt/local/lib/ruby/vendor_ruby_tmp /opt/local/lib/ruby/vendor_ruby

    This fixes the error and everything runs well for me, but I would like to hear the experts out there about why there are separate vendor_ruby and site_ruby.

    That’s it. Hope you find this helpful and please report any problems.

     

    8 responses to “Setting up Ruby on Rails, MySQL, Mongrel, memcached, and RMagick using MacPorts on Mac OS X 10.5 Leopard”

    1. Hello,

      Thanks for that post, it is very useful for me as I’m new to Mac OS and I wanted to install all those things there.

      I think I don’ understand is that whenever I restart my computer, the file /tmp/mysql.sock is gone and I must to create again the symbolic link. Do you have any recommendations or solution for this problem?

      Thanks.

    2. depi, this may help you.

      But the MySQL socket is actually in /opt/local/var/run/mysql5/mysqld.sock, so I think if you have this, you should be fine. Is MySQL server running on your machine? Do:

      ps -ef | grep mysql
      

      Do you see it running? Can you connect to it?

    3. The second part of step 6 does not work, I cant seem to create the Plist file in the Property List Editor. any ideas?

    4. nevermind, I created it.

    5. Just a quick heads up for those developers not wanting to run memcached permanently on their machines. You can simply run it from the command line using:

      /opt/local/bin/memcached -d -m 64 -u www -l <yourIP> -p 11211
      

      Alternatively, just download the cache_fu plugin and use the free memcached_ctl command it gives you (written by atmos):

      # script/memcached_ctl stop
      # script/memcached_ctl start
      # script/memcached_ctl status
      

      to start, stop and monitor the status of your local memcache setup.

    6. Hi

      As a fresh blog.rayvinly.com user i only wanted to say hi to everyone else who uses this board :>

    7. [...] http://rayvinly.com/articles/2007/11/29/setting-up-ruby-on-rails-with-mysql-on-mac-os-x-10-5-leopard…; [...]

    Leave a reply