Ruby, MySQL and Oracle on MacOS X Lion

One of the drawbacks on being an early adopter is the amount of work needed to make all the pieces fit.

I’ve upgraded to MacOS X Lion on the day one, and, since then, accessing Oracle Databases has been a pain. The reason is that the Oracle Instant Client is broken on Lion, and Oracle has yet to release a fix (or even acknowledge the issue).

Fortunately, some good souls found that the 32-bit version of the Instant Client still worked, and so my journey begins. So I’m writing this small guide, mainly to remember myself of all the work I had to do.

Step 1: Get a 32-bit Ruby

This is one of the easiest parts, since it’s well documented on the RVM page: http://beginrescueend.com/support/troubleshooting/#i386. I personally chose to get a clean RVM environment before doing this, so I ran a rvm implode and then reinstalled it.

Once RVM was back and clean, I installed REE, my Ruby of choice, using the documented flags to force a 32-bit build:

export CC=/usr/bin/gcc-4.2
rvm_archflags="-arch i386" CFLAGS='-m32' CXXFLAGS='-m32' LDFLAGS='-m32' rvm install ree
rvm use ree --default

Step 2: Install the oci-8 gem using the 32-bit Oracle Instant Client

Get the 32-bit version of the Instant Client and its SDK on the following address: http://www.oracle.com/technetwork/database/features/instant-client/intel-macsoft-096467.html.

I usually extract the files to /usr/local/oracle. Once extracted, export it to the DYLD_LIBRARY_PATH and install the gem, using the same flags as before:

export DYLD_LIBRARY_PATH=/usr/local/oracle/instantclient_10_2
rvm_archflags="-arch i386" CFLAGS='-m32' CXXFLAGS='-m32' LDFLAGS='-m32' gem install ruby-oci8

Step 3: Damage Control – check your other gems

It turns out that, once my Ruby is running on 32-bit, several other would also need to be compiled for that architecture. The specific problem I experienced was with the MySQL gem: my MySQL installation was a 64-bit one, and, while the gem installed without errors, it could not be loaded by the Ruby interpreter, since they would be running on different architectures.

So I had to download a 32-bit MySQL distribution and extract it to my Mac. I didn’t, however, installed it: I just extracted its files, then pointed the gem to those 32-bit libraries while compiling.

The command ended up pretty complicated, but worked fine:

gem install mysql2 -v 0.2.11 -- --with-mysql-config=/usr/local/mysql-5.5.15-osx10.6-x86/bin/mysql_config

If you are running a 32-bit installation of MySQL, you might not need to use this command, just install the MySQL gem as usual.

Step 4: Point to the right libraries

Add the new library paths to your ~/.profile:

# Oracle and MySQL 32-bit
export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:/usr/local/mysql-5.5.15-osx10.6-x86/lib:/usr/local/oracle/instantclient_10_2

 

And that’s it. Hope this information helps someone.

Deixe uma resposta

Preencha os seus dados abaixo ou clique em um ícone para log in:

Logotipo do WordPress.com

Você está comentando utilizando sua conta WordPress.com. Sair / Alterar )

Imagem do Twitter

Você está comentando utilizando sua conta Twitter. Sair / Alterar )

Foto do Facebook

Você está comentando utilizando sua conta Facebook. Sair / Alterar )

Foto do Google+

Você está comentando utilizando sua conta Google+. Sair / Alterar )

Conectando a %s