Read the latest web development and design tips at Fred Wu's new blog! :-)
Poke me on GitHub

Using Ruby MySQL Gem with MAMP 1.8.x on Snow Leopard

Being primarily a PHP developer, I always use an AMP package no matter what development platform I am on. So when it comes to developing Ruby/Rails applications on the same platform, I’d like to use what is already available.

Mike Boone has posted a very useful tutorial on how to get MySQL gem and MAMP 1.7.2 up and running. So, to recap and make the tutorial compatible with Snow Leopard and MAMP 1.8.x, here is what you need to do:

  1. Download the latest MAMP dmg file.
  2. Download the 1.8.2 (or whichever the latest one you could find) components file from this page.
  3. Unzip, mount the dmg, then copy the MySQL source file (mysql-5.1.37.tar.gz) to somewhere on your hard drive.
  4. Untar the MySQL source file, and `cd` to the source file directory.
  5. Compile the library:


    $ ./configure --with-unix-socket-path=/Applications/MAMP/tmp/mysql/mysql.sock --without-server --prefix=/Applications/MAMP/Library

    $ make -j2

  6. Copy the compiled libraries into MAMP:

    $ cp libmysql/.libs/*.dylib /Applications/MAMP/Library/lib/mysql

  7. Copy the MYSQL headers into MAMP:


    $ mkdir /Applications/MAMP/Library/include

    $ cp -R include /Applications/MAMP/Library/include/mysql

  8. Install the Ruby MySQL Gem, on Snow Leopard:


    $ sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-config=/Applications/MAMP/Library/bin/mysql_config

    On Leopard:


    $ sudo env ARCHFLAGS="-arch i386" gem install mysql -- --with-mysql-config=/Applications/MAMP/Library/bin/mysql_config

Enjoy!

EDIT @ 2009-11-23: If you’re still experiencing problems (perhaps with RVM), try adding “/Applications/MAMP/Library/bin/” to your $PATH in “~/.bash_profile”.

  • Digg
  • DZone
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • LinkedIn
  • Live
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • Twitter

Related posts

Tags: , , ,

Comments Section

29 Responses to “Using Ruby MySQL Gem with MAMP 1.8.x on Snow Leopard”

Sidebar might be covered by comments ... consider it a feature! ;)
  1. 1

    Thank you SO much! Been wanting to tool around with Rails and was embarassed at being stopped in my tracks with something so easy.

  2. 2

    Hmm. Everything went well until the last step. I’m getting a big string of output like:

    Installing ri documentation for mysql-2.8.1...

    No definition for next_result

    No definition for field_name

    No definition for field_table

    No definition for field_def

    No definition for field_type

    ...

    Installing RDoc documentation for mysql-2.8.1...

    No definition for next_result

    No definition for field_name

    No definition for field_table

    No definition for field_def

    ...

    Total noob when it comes to Ruby…just trying to get mysql (with MAMP, of course) working so I can toy around and start learning. Any ideas? I tried the last update tip, too, and added to my PATH variable.

    As far as I can tell, everything went well with the make, copying, etc. I was watching what happened and I do have new files where I’d expect them to be in the MAMP folder.

    I’m on MAMP 1.8.3, and that’s the source I downloaded as well. Running Snow Leopard 10.6.2… running the standard ruby that comes with OS X:

    ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0]

    Also, running rubygems 1.3.5, which I installed manually, according to instructions on some site I found earlier. gem normally seems to work with the few gems I’ve installed, but not this one.

    Thanks in advance for any help.

  3. 3

    OK, upon closer inspection, it would appear that the gem did install, but the documentation was not built. All of those documentation errors obscured the “1 gem installed” line. So, if there is any advice on how to get the documentation built, that would be fabulous, but actually it looks like the gem is installed and working, so thanks for the post!

  4. 4

    @Dru Kepple – I’m also getting the same documentation problems. I’m running the same ruby version you are as well. Have you had any problems running Ruby locally with the steps listed on this site?

  5. 5

    I followed your instructions with no errors, but when I do rake db:migrate, I get:

    $ rake db:migrate
    (in /Users/rahil/Sites/test)
    rake aborted!
    uninitialized constant MysqlCompat::MysqlRes

    (See full trace by running task with --trace)

  6. 6

    I actually never had any problems using the Ruby MySQL gem with MAMP mysql. I did not have to compile it. I had to adjust my path and provide the path to the MAMP socket, and everything just worked.

    But now I am using RVM to roll back to ruby 1.8.7 for a project. And so I need to install the mysql gem for my rvm ruby 1.8.7. I already have the /Applications/MAMP/Library/bin in my path. Hmmmmmm

  7. 8

    Thanks, was very helpful to me :)

  8. 9

    This did the trick. Thanks for posting.

  9. 10

    Right on, thanks for the MAMP help!

  10. 13

    This still works with Snow Leopard and MAMP 1.9.x

    This was the best solution I found after looking for two days on various sites. Thanks a ton!

  11. 15

    Thanks a lot mate, just got it working as per your instructions with MAMP 1.9.2 on SL 10.6.4

  12. 19

    Macports also changes the profile paths, potentially changing your config

  13. 21

    [...] 相關內容參考Using Ruby MySQL Gem with MAMP 1.8.x on Snow Leopard。   發表迴響 [...]

  14. 22

    I like the tutorial; it was easy to follow and worked well.

    Now, how would one revert to the Mac’s built in MySQL version?

    I assume I will need to change $PATH again…

    Any help is much appreciated!

  15. 23

    Thanks so much!!!
    I’ve been cracking my head on this the all day. Life saver!

  16. 25

    An updated version working with cmake (which is now the build system for MySQL 5.5): http://blog.mirotin.net/?p=35

  17. 28

    Thank you so much! This actually worked out for me!

  18. 29

    It is failing for me and giving error:

    libtool: link: cannot find the library `’ or unhandled argument `Setup/mysql-5.1.44/unittest/mytap’

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>