Installing postgres gem on OSX (Leopard with MacPorts PostgreSQL82)
Unfortunately, out of the box, the postgres gem fails to install with the MacPorts postgres82-server install. There are two problems. The first is it can’t find pg_config. The second is incorrect architecture detection (thanks to Andreas Flierl at the RubyForge postgres module forums for pointing out the fix).
ERROR: Error installing postgres:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb install postgres
extconf.rb:73: command not found: pg_config --bindir
The fix for this one is to fix the path temporarily:
export PATH=/opt/local/lib/postgresql82/bin/:$PATH
Then when we retry the gem installation, we’ll get the following error(s):
postgres.c:41: error: static declaration of ‘PQserverVersion’ follows non-static declaration /opt/local/include/postgresql82/libpq-fe.h:262: error: previous declaration of ‘PQserverVersion’ was here postgres.c:41: error: static declaration of ‘PQserverVersion’ follows non-static declaration /opt/local/include/postgresql82/libpq-fe.h:262: error: previous declaration of ‘PQserverVersion’ was here postgres.c: In function ‘Init_postgres’: postgres.c:2676: error: ‘pgconn_protocol_version’ undeclared (first use in this function) postgres.c:2676: error: (Each undeclared identifier is reported only once postgres.c:2676: error: for each function it appears in.) postgres.c:2677: error: ‘pgconn_server_version’ undeclared (first use in this function) postgres.c: In function ‘Init_postgres’: postgres.c:2676: error: ‘pgconn_protocol_version’ undeclared (first use in this function) postgres.c:2676: error: (Each undeclared identifier is reported only once postgres.c:2676: error: for each function it appears in.) postgres.c:2677: error: ‘pgconn_server_version’ undeclared (first use in this function) lipo: can't open input file: /var/tmp//ccBatpen.out (No such file or directory) make: *** [postgres.o] Error 1
These are fixed by specifying a specific architecture to use.
The following commands worked well for me:export PATH=/opt/local/lib/postgresql82/bin/:$PATH sudo env ARCHFLAGS="-arch i386" gem install --remote postgres
Learning Ruby
I’ve recently been exploring Ruby. I
thought that I’d try my hand at blogging with a purpose. That said, I’m
going to blog my progress as I learn this intriguing language. <br
/>
Ruby describes itself as a mix of Smalltalk, Python, and
Perl. Some of its syntax seems weird and awkward at first, but I feel
part of that is due to the fact that its even more lax than Perl about its syntax.
One of the challenges I faced was finding a decent set of examples showing
the syntax and quirks of the language in action. I originally tried to use
the online version of Programming Ruby, but I found that it was not a great choice for me. I need
examples, and plenty of them.
I managed to overcome some of the
limitations of this gude through general surfing (I wish I’d kept track of
those web pages), and through playing with irb. Irb is neat. I
think it stands for Interactive Ruby. Its a shell-like interface to
Ruby. If you
enable tab completion, then irb becomes even more valuable to the learner, as
you can explore the classes, variables, and methods more easily.
<br
/>More recently, I found a rather oddly written book, Why’s (Poignant) Guide to Ruby. I find the banter to be horribly annoying, but after the
first chapter I learned to skip over it. Buried in between inane and
unnecessary blather, there’s tons of examples, with decent explanations to
boot. I think Why could reduce the size of the book by over 75% and
call it Why’s Concice Guide to Ruby instead.
Something else I
played with is Ruby on Rails. I
walked through the first two tutorials (first,
second).
I’m not sure I like how automagically it does some of the database stuff, but I intend to learn how it works so I can override it all. I’ll post
about that when I learn about it. For now, though, the most
interesting thing I got was from scanning through Amy’s blog entry about the
MVC: Most Vexing Conundrum. MVC or
Model View Controller is a design model that I intend to learn more about.
For now though, I’m still making my way through Why’s
guide.
Setting up a blog with Typo
Sometimes you just have to try something for yourself. Today, that was setting up my own blog on my own server.
Yesterday, I posted my first article about my experiences with Ruby at a seldom used LiveJournal of mine. I eventually decided that it made more sense to have this on my own server, running my own choice of software on my own choice of OS (FreeBSD).
A bit of googling led me to Typo. Typo is a blogging package written using the Ruby on Rails framework.
The package looked slick, has themes, and other nice features, so I figured I’d give it a try. That was the easy part. I’ve spent the better part of my evening upgrading bits and pieces of software as a result.
I started off with the easy bits: upgrading Ruby and rails. This really was the easy part. In FreeBSD, it was a matter of installing the Ruby port, followed by the rubygem-rails port. This port automatically installed all the necessary dependencies, including RubyGems. RubyGems is a package manager type of thing for Ruby. It works well. It reminds me of CPAN for Perl.
Afterwards, I learned I would need FastCGI for good performance with any Rails app. Naturally, I had to upgrade Apache —but couldn’t do it the easy way without cutting off web service for my users for an unacceptable period of time. So I had to build a temporary copy of Apache 2.2 to test the new configuration. After I was satisfied that the temporary copy worked, I switched it on. I then was able to purge the old packages and dependencies, build the new Apache 2.2 package, install, configure, and then test it. I was finally ready to switch off the temporary Apache install and enable the new Apache packages.
Now my system was ready for FastCGI. FastCGI is a nifty way of speeding up applications that are slow to start, but fast once started—like Ruby and Perl applications.
Because I wanted to put this blog at http://www.royhooper.ca/blog/, I had to follow alternate install instructions. Of course this didn’t go smoothly either. I had to futz around with my configuration, looking for the culprit. Eventually, with the help of trusty Google, I ran across two [1, 2] helpful web pages.
I’m fairly happy with the results. I’ll definitely have to play with this theme to make it look the way I want, but I like how it works.
