November 21, 2011
Installing PostgreSQL Server on OS X 10.6 using MacPorts

Installing PostgreSQL server using MacPorts used to be a simple matter. For some reason, using the latest MacPorts 2.0.3 on Snow Leopard seems to break the relatively simple install process.

The main problem is the install process doesn’t create the postgres user and group. This is done during the destroot phase of the install process, which doesn’t seem to be run automatically anymore.

Luckily, you can manually run the destroot phase. The following example shows you how to install PostgreSQL 8.4 server:

sudo port install postgresql84-server
sudo port destroot postgresql84-server
sudo port clean postgresql84-server

Now you can happily create the defaultdb and assign the proper user and group ownership.

Note that the problem only seems to happen on Snow Leopard, and not on Lion.

10:19pm
(View comments  
Filed under: MacPorts OS X 
October 29, 2011
Compiling MacPorts Python on Lion using GCC

Edit: As of November 21, 2011, this is fixed. See https://trac.macports.org/ticket/30031 for more information.

I use MacPorts for my Python installations. With the latest Xcode 4.2, MacPorts uses clang as the default compiler. This causes all sorts of fun with decimal arithmetics, such as:

$ python
Python 2.6.7 (r267:88850, Oct 28 2011, 17:33:57) 
[GCC 4.2.1 Compatible Apple Clang 3.0] on darwin
>>> from decimal import Decimal
>>> Decimal(10)/Decimal(5)
Decimal('8.955976040786690048E-10')

Note that Python is compiled with Clang 3.0.

The fix is to compile Python with GCC. The easiest way to accomplish this is to edit the Portfile and for MacPorts to use a specific compiler.

MacPorts keeps a local version of available Python ports at:

/opt/local/var/macports/sources/rsync.macports.org/release/tarballs/ports/lang/

For example, Python 2.6 is at:

/opt/local/var/macports/sources/rsync.macports.org/release/tarballs/ports/lang/python26

Edit Portfile and add the following line:

configure.compiler gcc-4.2

I add it in the # ensure that correct compiler is used section, before configure.cc is used, like so:

# ensure that correct compiler is used
configure.compiler gcc-4.2
build.args-append       MAKE="${build.cmd} CC=${configure.cc}"
destroot.args-append    MAKE="${destroot.cmd} CC=${configure.cc}"

Now recompile python:

sudo port -n upgrade --force python26

After waiting for a while everything will be OK again:

$ python
Python 2.6.7 (r267:88850, Oct 29 2011, 21:09:34) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
>>> from decimal import Decimal
>>> Decimal(10)/Decimal(5)
Decimal('2')

Note that Python is now compiled with GCC 4.2.1.

The steps I described is a hack and the next time you perform port selfupdate your changes will be wiped out. But I imagine this bug will be fixed before you have to update Python again. If you want to do things properly by setting up your own local repository, see the MacPorts guide.

You should obviously recompile all versions of MacPorts Python you use, as this bug isn’t isolated to 2.6.

For more detailed discussions on the bug, see:

For information on selecting the right compiler for MacPorts, see the wiki page.

10:16pm
(View comments  
Filed under: MacPorts OS X 
May 13, 2011
MacPorts Maintenance

I use MacPorts to install add-ons for my Mac in an isolated way from the core OS. This is the routine I go through to keep my ports up to date and as lean as possible.

I typically run updates once a month, and this is the procedure I use.

The first thing is to update MacPorts itself:

sudo port selfupdate

I keep older versions of ports around for one update revision in case I need to roll back, so let’s remove those inactive ports.

sudo port uninstall inactive

Are any leaves that we can get rid of1:

port echo leaves

To uninstall the leaves:

sudo port uninstall leaves

Now we can upgrade our ports:

sudo port upgrade outdated

And you’re all set until the next update.


  1. http://guide.macports.org/#using.common-tasks. You can mark certain ports as requested, preventing them from being reported as leaves, i.e.: sudo port -d setrequested autoconf help2man p5-locale-gettext m4 automake libtool pkgconfig 

9:00am
(View comments  
Filed under: MacPorts tips OS X