Posts Tagged snow leopard

Setting up Rails 3 on Mac OSX Snow Leopard 10.6.4

I finally made the complete switch to Mac this weekend.  I have been using my iMac at work for about a year and I love it, but I have been holding on to my Dell laptop and more and more every day I feel like throwing it through a window, so I decided to bite the bullet and buy a Macbook Pro so I could be more productive at home.  Here is a step by step guide of how I set it up to work with Rails 3.

1. Install git and RVM

RVM is a great way to manage multiple ruby versions on your Mac, and it also makes installing any version dead simple.  You will need to install “git” before you can install RVM.  I downloaded the git DMG from here:

http://git-osx-installer.googlecode.com/files/git-1.7.3.2-intel-leopard.dmg

Install git from the DMG and then you can install RVM afterwards.  Note that you will have to restart your terminal session in order to use the git command.

Install RVM by issuing the following commands in your shell:

Now you should be good to go with RVM. Here is the install guide if you run into any problems: http://rvm.beginrescueend.com/rvm/install/

Install a C Compiler (by installing XCode)

You will need a c compiler to install ruby using RVM.  You can download XCode, which has a c compiler, from the Apple website.  I downloaded the iOs/XCode package since i will probably be developing iPhone apps as well.  This is a mamoth download (3+ GB), so be prepared to wait a while.

If you dont feel like waiting that long for the download, pop in the OSX DVD that came with your Mac and when the startup screen appears, choose “Optional Installs”, and you can install XCode from there (without iOS stuff).

Install Ruby 1.9.2

cowboycoded$  rvm install 1.9.2

Simple as that!  This may take a few minutes to compile and install.  RVM will also install RubyGems, so its not necessary to do that manually.  Snow Leopard ships with Ruby 1.8.7, so you will need to switch to version 1.9.2 after you install it with RVM.  Use RVM to switch versions.

cowboycoded$  rvm 1.9.2

Verify that you are using 1.9.2

cowboycoded$  ruby -v

Set 1.9.2 as the default Ruby in RVM, so you don’t have to switch every time you open a new shell

cowboycoded$  rvm --default use 1.9.2

Install Ruby on Rails 3

cowboycoded$  gem install rails

This will install Rails 3 and all of its dependencies.  At the time of this writing the current version was 3.0.3.  I use MySQL for all of my apps, so I need to install that also.

Download and install MySQL server

http://dev.mysql.com/downloads/mysql/

Its probably easiest to download the DMG and install it that way.  Get the 64 bit DMG if you are using Snow Leopard.  Probably a good idea to install the MySQL Startup Item that is in the DMG as well.  This will start MySQL when your Mac boots.

After you install you can use the Startup Item to start MySQL manually:

cowboycoded$  sudo /Library/StartupItems/MySQLCOM/MySQLCOM start

If you are using the mysql gem (v2.8.1), then you will likely run into a problem when you bundle install. Install the gem manually using this command instead:

cowboycoded$  sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

Test it out

You should have everything you need at this point.  Fire up a new rails app and make sure everything worked:

cowboycoded$  rails new test_app
cowboycoded$  cd test_app
cowboycoded$  bundle install
cowboycoded$  rails s

Tags: , , , , ,

Snow Leopard upgrade pain…

So I decided to upgrade to Snow Leopard last week in order to use the iOS SDK and crank out some iPhone/iPad apps.  As with any major upgrade I was expecting a few minor problems, but it really wreaked havoc on my Rails development environment.  The first problem was with MySQL.  The previously installed version did not work at all after the upgrade.  I could not get the server to start.  I downloaded the newest DMG of mysql server and installed it on my Mac.  I chose 32 bit MySQL, since I mistakenly thought my Mac was 32 bit after I ran the “uname -a” command and it showed i386.  So after some experimenting and further research, I downloaded the 64 bit DMG, since my Mac is actually 64 bit capable (if your processor info says Intel Core 2 Duo, then you are 64 bit).  In order to keep my existing data from the crapped out MySQL server (prior install for Mac 10.5), I had to stop the running server, delete the contents of the mysql data directory, copy my old data from the old data dir, and restart the server.  This fixed my database problems.  The next odd thing was my C Compiler.  I tried to install the mysql gem and received this error:

Building native extensions.  This could take a while…
ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.

/Users/me/.rvm/rubies/ruby-1.9.2-rc2/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient… /Users/me/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/mkmf.rb:368:in `try_do’: The complier failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /Users/me/.rvm/rubies/ruby-1.9.2-rc2/lib/ruby/1.9.1/mkmf.rb:435:in `try_link0′

Looking at the mkmf.log, showed me that it was having problems with the readline library.  Apparently the system readline installed with Snow Leopard does not play well with the ruby install.  So  I ran the following and RVM was able to use the correct readline library:

rvm package install readline
rvm install 1.9.2 -C --with-readline-dir=$HOME/.rvm/usr

This solved the readline problem, but another problem appeared after this:

ld: in /usr/local/lib/libxml2.2.dylib, file was built for i386 which is not the architecture being linked (x86_64)

There were are also problems with SQLite and libxslt.  I found this post which solved all 3 of these problems. Thanks Mark!

After correcting these problems, Ruby 1.9.2 installed fine with RVM and I was able to install the mysql gem without errors.

Tags: , , ,