Entries in Ruby (2)

Friday
Apr302010

Problem installing git using homebrew

I finally got to the bottom of my git install issue using homebrew.

If you’re not familiar with homebrew it’s a package manager (sort of) for OS X but all the “packages” are built on your machine. It’s really a scripted installer written in Ruby. Here’s a link to a more thorough explanation: Homebrew post on EngineYard.com

Homebrew is great, and I’ve been using it for all of my new installs but I was having problems installing git. I kept getting this error using this command: sudo brew install -v git <= the ‘-v’ is for verbose output

In file included from /usr/local/include/curl/curl.h:36,
                 from http.h:6,
                 from remote-curl.c:5:
/usr/local/include/curl/curlrules.h:134: error: size of array ‘__curl_rule_01__’ is negative
make: *** [remote-curl.o] Error 1

Some backstory: I am on snow leopard but that is relatively recent. After making the transition a few weeks ago I had countless errors with the whole 32/64-bit architecture thing. What I realized in this instance was that since I had compiled curl from source when I was on leopard I needed to recompile. (I’ve had to recompile/reinstall just about everything after the upgrade (postgres, ruby, erlang, etc…)). Turns out, after downloading the latest curl, and compiling/installing it from source. I was able to install git using homebrew without a problem.

Note: I am not sure this is a git specific issue when installing with homebrew. It could be a general issue with homebrew and my system as homebrew uses curl/libcurl to get files and such. I suspect that this would have happened for any homebrew install but I have no evidence to back that up.

Wednesday
Oct072009

Trouble with the Postgres Ruby gem on OSX 10.6 (pg gem on Snow Leopard)

I recently (i.e. earlier today) decided to stop cheating and using the Postgres pure Ruby (postgres-pr) adapter and switch to the real-deal compiled version (formerly known as ‘postgres’ now known as just ‘pg’). I had been putting this off because all prior attempts to sudo gem install postgres had failed with esoteric messages which I will likely never understand.

It also happens that I just upgraded to OS X 10.6 (AKA Snow Leopard). What better time to try again?

Step 1 - Out with the old

gem uninstall postgres-pr

Select gem to uninstall:
1. postgres-pr-0.4.0
2. postgres-pr-0.5.1
3. postgres-pr-0.6.1
4. postgres-pr-0.6.1
5. All versions

I chose option 5

Successfully uninstalled postgres-pr-0.4.0
Successfully uninstalled postgres-pr-0.5.1
Successfully uninstalled postgres-pr-0.6.1
Successfully uninstalled postgres-pr-0.6.1

I don’t know why there were two postgres-pr-0.6.1 perhaps one had been installed in my local .gem directory and the other in the system gem dir.

Step 2 - Installing the newness

sudo gem install pg

Wait for it…

FAIL! `ERROR: Error installing pg:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
extconf.rb:1: command not found: pgconfig —version
ERROR: can’t find pg
config.
HINT: Make sure pg_config is in your PATH `

Crap, that sucks. But there is a glimmer of hope. Note the “HINT”…hmm… thanks fellas!

Step 3? - Where is that pg_config?!

Through the magic of the command line we can search for it. Drop this on the command line.

mdfind pg_config|grep bin|uniq

Your results will probably be different but mine are: /Library/PostgreSQL/8.3/bin/pg_config
/usr/local (from old Mac)/bin/pg_config
/usr/local (from old Mac)/pgsql/bin/pg_config
/usr/local (from old Mac)/src/postgresql-8.2.5/src/bin/pg_config
/usr/local (from old Mac)/src/postgresql-8.2.5/src/bin/pg_config/pg_config
/usr/local (from old Mac)/src/postgresql-8.2.5/src/bin/pg_config/pg_config.c
/usr/local (from old Mac)/src/postgresql-8.2.5/src/bin/pg_config/pg_config.o

Pay attention to the first line that’s where the elusive ‘pg_config’ is hiding. (For the record, I have no idea why this file is needed or what it does. Perhaps some sort of pg config?) See the comments below for an explanation by my friend Rhett.

Note to reader: At this point I got distracted and tried to delete that local (from old mac) folder and almost ran an rf with recursive force on my usr/local directory (by almost… I mean I did run it but thankfully a sudo is required for this operation. For all my complaining about having to use Sudo it totally saved my ass. I will henceforth never complain about having to type it in all the time.)

Step… to hell with the steps because we have derailed.

Time to try the install again. Drop the path on the command as part of the install like so.

PATH=/Library/PostgreSQL/8.3/bin:$PATH sudo gem install pg

This yields a new, somewhat more confusing and more verbose error. The meat of it is:
In file included from compat.c:16:
compat.h:38:2: error: #error PostgreSQL client version too old, requires 7.3 or later.

I have even less of an idea what to do with this… thankfully, after some googling it turns out this is a common issue compiling the pg gem on Snow Leopard and the fix is easy.

So, combining the first fix with this new one we get:
PATH=/Library/PostgreSQL/8.3/bin:$PATH sudo env ARCHFLAGS='-arch i386' gem install pg

Running this we get:

Building native extensions. This could take a while...
Successfully installed pg-0.8.0
1 gem installed

Sweet!!! No more postgres-pr. We are now on the very fast pg gem for Postgres on Ruby.