From Zero to Rails Hero in 11 Easy Steps (Installing Rails on OS X 10.6.5)

This is the easiest, fastest and best-to-develop-in way to get a rails dev stack up and running on OS X 10.6 (Snow Leopard).

I actually find that it’s pretty easy, if everything is done in the right order.

  1. Install XCode
  2. Install Homebrew
    $ ruby -e "$(curl -fsSL https://gist.github.com/raw/323731/install_homebrew.rb)"
  3. Install git using homebrew
    $ brew install git
  4. Install mysql using homebrew
    $ brew install mysql
  5. Install rvm (and follow the instructions to set up bash and don’t forget to open a new terminal window)
    $ bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
  6. Install Ruby Enterprise Edition
    $ rvm install ree
  7. Make REE the default Ruby
    $ rvm use ree --default
  8. Tell rubygems to not install rdocs
    Put the following lines in ~/.gemrc

    install: --no-rdoc --no-ri
    update: --no-rdoc --no-ri
  9. Install Passenger
    $ gem install passenger

    Now follow that up by running the install script (and follow the directions)

    $ ./passenger-install-apache2-module

    At the end of the install process it will give you instructions to add 3 lines to the “Apache configuration file”, but it won’t tell you *where* your apache config file is. It’s at /etc/apache2/httpd.conf

  10. Restart Apache
    At this point, if you’re using 10.6.5, you might do a sudo /etc/apachectl restart and run into the following error:
    /usr/sbin/apachectl: line 82: ulimit: open files: cannot modify limit: Invalid argumentTo fix this, edit /usr/sbin/apachectl and change ULIMIT_MAX_FILES to an empty string.

    Now you can restart apache.

  11. Install PassengerPane 1.3 www.fngtps.com/files/2/2009/09/PassengerPane-1.3.tgz

BOOM! Done.

Well, for me, I had to `gem install isolate` and Rubymine and then I was done, but you get the idea. Just load up the Passenger Preference Pane, point at site at a rails project on your hard drive, and load it up in your browser. Assuming your rails app will boot, you should be good to go!

  • EvilTed

    This works great for a workstation, but what about 10.6.5 server?
    This comes with MySQL pre-installed in some really stupid locations which makes removing it a royal PITA 🙁

    Also you don’t seem to be install the MySQL Gem.
    This required a bit of work to get installed on 10.6.5 Server and the default install of MySQL is still the one running after your install.

    It probably requires to just not install MySQL via brew in your step and to just use the default install and fetch the client binaries (for the installed version) and build against them.
    The latest binaries (5.0.91) for 10.6.5 are available from:

    http://support.apple.com/kb/HT4006

    but substitute MySQL-54 instead of MySQL-49 as listed.

    If you add the path to the bin, lib and include folders of the binary install, gem install mysql works.

    Now, if you know a clean way to get brew to remove the default MySQL and build everything, I’m all ears 🙂

    Thanks for the article – some nice bits in it!

    ET

    • BJ Clark

      I have no experience with OS X Server newer than ~10.2. 🙂

  • Evil Ted

    OK, it was a pretty interesting exercise, but here is how to do it for OS X Server 10.6.x.
    This was gleaned from numerous sites and documents and carefully pieced together, so if anyone recognizes any of their stuff here, thanks in advance 🙂

    I think it makes a nice addition to your tutorial.

    1. Remove default mysql installation

    $ rm -rf /Library/StartupItems/MySQLCOM
    $ rm -rf /Library/PreferencePanes/My*
    $ vim /etc/hostconfig and removed the line MYSQLCOM=-YES-
    $ rm -rf ~/Library/PreferencePanes/My*
    $ rm -rf /Library/Receipts/mysql*
    $ rm -rf /Library/Receipts/MySQL*
    $ rm -rf /var/db/receipts/com.mysql.*

    Also remove all files from these locations:

    /usr/bin Client programs
    /var/mysql Log files, databases
    /usr/libexec The mysqld server
    /usr/share/man Unix manual pages
    /usr/share/mysql/mysql-test MySQL test suite
    /usr/share/mysql Miscellaneous support files, including error messages, character set files, sample configuration
    files, SQL for database installation
    /var/mysql/mysql.sock Location of the MySQL Unix socket

    NOTE: Most Important
    OS X Server uses launchd to start the server at boot and uses the /System/Library/ location.

    You need to unload it
    $ launchctl unload -w /System/Library/LaunchDaemons/org.mysql.mysqld.plist

    then delete it
    $ rm /System/Library/LaunchDaemons/org.mysql.mysqld.plist

    —————————————————————————————————-

    2. Install mysql via homebrew

    $ brew install mysql

    —————————————————————————————————-

    3. Edit /etc/my.cnf
    You need to set the socket location and the ‘tmp’ directory location (more on this in next section).

    $ vim /etc/my.cnf

    [client]
    port = 3306
    socket = /tmp/mysql.sock

    [mysql.server]
    user=mysql
    basedir=/usr/local/var/mysql

    [mysqld]
    port = 3306
    socket = /tmp/mysql.sock
    tmpdir=/usr/local/var/mysql/tmp

    —————————————————————————————————-

    4. Configure mysql

    a) create mysql user and groups
    # create the MySQL group
    dscl . create /Groups/mysql
    # give it some group id
    dscl . create /Groups/mysql gid 296
    # create a MySQL user
    dscl . -create /Users/mysql
    # make the MySQL user a member of the MySQL group
    dscl . append /Groups/mysql GroupMembership mysql
    # change ownership to mysql
    cd /usr/local/var/mysql
    chown -R mysql .
    chgrp -R mysql .

    b) Make a tmp directory. This gets rid of the default errors you get using mysql_install_db.

    $ cd /usr/local/var/mysql
    $ sudo mkdir tmp
    $ sudo chown mysql:mysql tmp
    $ sudo chmod 777 tmp

    c) install mysql tables
    mysql_install_db –user=mysql

    d) Create a root password
    mysqladmin -u root password your_root_password

    e) Test launch as root
    mysqld_safe –user=root &
    $ ps -e | grep mysqld # should show running server process as root
    $ killall mysqld

    f) Test launch as mysql
    $ mysqld_safe –user=mysql &
    $ ps -e | grep mysqld # should show running server as mysql
    $ killall mysqld

    g) Configure to launch mysql server on boot with launchd

    $ cp /usr/local/Cellar/mysql/5.x.xx/com.mysql.mysqld.plist /System/Library/LaunchDaemons

    $ vim /System/Library/LaunchDaemons/com.mysql.mysql.plist

    change user name from ‘root’ to ‘mysql’

    UserName
    mysql

    $ cd /System/Library/LaunchDaemons

    $ launchctl unload com.mysql.mysqld.plist

    $ launchctl load com.mysql.mysqld.plist

    h) reboot server and test

    $ sync;sync;reboot

    wait for server to reboot and check server process is running as user ‘mysql’

    ps -e | grep mysqld

    Et Voila!

    Now gem install mysql works flawlessly and you have an upgraded version of mysql on OS X Server 10.6.x

  • Robert Graff

    Step 9:

    $ passenger-install-apache2-module

    instead of

    $ ./passenger-install-apache2-module