Ruby on Rails and MAMP PRO – It’s a jungle out there.

Introduction

If you’re looking for the how to, and have no intention reading my rambling, go on and scroll down a little bit 🙂

So I’ve started learning Rails for a while now. I’ve been exploring a lot in the world of ruby and rails. Found tons of interesting stuff, watched a lot of screencasts, graduated from Rails for Zombies, and much more, but now, about a week ago I decided to finally get my hands dirty on my own Mac OS X Lion, and thats where it all started. Finally, today I decided not to give up and finish setting up Rails.

MAMP PRO Is a pit of bugs.

I develop with PHP a lot, and MAMP Pro has worked for me flawlessly up until now. I love the nice graphical interface I get to manage my local domain hosts (myproject.dev/), etc. and probably because of that I’ve managed to overlook all the bugs (for example not being able to reboot/shutdown my mac, until I’ve force quitted MAMP), but this day changed my perspective a little bit. But that is not what this story is about.

 

MAMP PRO and Ruby On Rails

This is the part where it got bad. At first, I thought – hey – wouldn’t it be nice to run Rails with the same MySQL server as MAMP, but hey – MAMP has moved MySQL installation to their local directory. Not only that, but it is missing files, so I can’t compile Ruby gems to install with MAMP.

So I went ahead and searched. I found some useful posts, or at least at that moment I thought so, about MAMP And Ruby: [ Article 1 ] , and [ Article 2 ] , but all I did was screw up my system.

In the end, I wish in all the hours I spent on Google, that I found a blog post like this one. It turns out, installing MAMP Pro and Ruby On Rails, and setting them up is super-duper-easy.

 

How to install Ruby on Rails 3.2.1 with Ruby 1.9.3 and MAMP PRO 2.0.1

First of all. If you don’t already have MAMP or MAMP PRO on your system, and you don’t have any intention of using PHP, stop reading this article. You don’t need MAMP Pro. Period. Take a look at POW and Brew. That’s all you need.

For the less fortunate – I assume you already have MAMP Pro, and have tried running gem install mysql2 without any success.
I use RVM, and if you don’t then I guess you have to be careful, and before certain commands need a sudo (like sudo gem for example), I’ll be writing about the RVM process, and yours shouldn’t be much different, just tweak it a little accordingly.

First, make sure you get to this point:

[plain]

~ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.3.0]
~ rails -v
Rails 3.2.1

[/plain]

Now that we’re on the same page this is what you do.

First install brew. Here is their installation documentation: https://github.com/mxcl/homebrew/wiki/installation
Basically all you need is this command:
[plain]mkdir homebrew && curl -L https://github.com/mxcl/homebrew/tarball/master | tar xz –strip 1 -C homebrew [/plain]

Now, MAMP stands for Mac- Apache, MySQL and PHP. I know you (and I) have MySQL already installed, but that isn’t going to cut it, as I said before – MAMP has moved MySQL to a different location. Even their mysql.sock file is somewhere else, so we’re going to install another MySQL on the system with

[plain] brew install mysql [/plain]

Now that you have MySQL – Just install the mysql2 gem

[plain] gem install mysql [/plain]

 

You also might want to make an alias for the mysql.sock file, which MAMP has also moved for us, by running:

[plain]sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock[/plain]

 

I would also suggest that you take a look at POW, it is a great, tiny, rails server for local development. Here is some information on Stack Overflow.
Thats it. I hope this helps you with MAMP and Rails, it sure as hell would helped me.

Cheers.

 

 

 

 

9 thoughts on “Ruby on Rails and MAMP PRO – It’s a jungle out there.”

  1. oh. your not actually linking the two here. my bad. is there a way at least you can use a gui for this other mysql install like mamp has?

  2. One quick note, the symbolic link will go away when you restart. I found a solution here: http://www.razorsql.com/docs/support_mysql_mac_mamp.html

    The good bit says:

    One way to change the socket location is to edit the MAMP start and stop scripts so that the mysql.sock location is the default. This can be done by editing the following files:

    /Applications/MAMP/bin/startMysql.sh
    /Applications/MAMP/bin/stopMysql.sh

    Replace
    socket=/Applications/MAMP/tmp/mysql/mysql.sock
    with
    socket=/tmp/mysql.sock

    Works like a charm!

Leave a Reply

Your email address will not be published. Required fields are marked *