🍎 Kuba Suder's blog on Mac & iOS development

Installing Sphinx on MacOSX from ports

Categories: Databases, Mac, Ruby/Rails Comments: 4 comments

A few days ago I spent a couple of hours trying to install the full text search engine Sphinx on my work computer in order to use it in my current project. I’m posting the details here, maybe this will save someone some time…

Firstly, if you’re like me and you look for some kind of binary package (like .dmg) first – sorry, there isn’t one. This leaves us two options: compiling Sphinx manually from the source, or using a package manager like MacPorts. I always avoid the first method if I have any other option, so I tried the ports.

Here’s the first problem: Sphinx requires MySQL, and while I have it on the disk of course, I’ve installed it from a dmg package, not from ports – which means it’s in a different path than ports expect and they have no idea where that is. I got scary errors like:

$ sudo port install sphinx
---> Building sphinx with target all
Error: Target returned: shell command " cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.​macports.​org_release_ports_textproc_sphinx/​work/​sphinx-0.9.7" && make all " returned error 2
Command output: sphinx.cpp: In member function 'virtual const char* CSphSource_MySQL::SqlError()':
sphinx.cpp:9397: error: 'm_tMysqlDriver' was not declared in this scope
sphinx.cpp:9397: error: 'mysql_error' was not declared in this scope
sphinx.cpp: In member function 'virtual bool CSphSource_MySQL::SqlConnect()':

So I had to override the options that ports pass to ./configure; the ports' man page wasn’t very helpful about how to do it, but luckily Google was. To do that, you need to pass the options as configure.args option to the port command. Here’s what I did (I had to clean the port first, otherwise it wouldn’t repeat the configure phase):

$ sudo port clean sphinx
---> Cleaning sphinx

$ sudo port install sphinx configure.args="--with-mysql-includes=/usr/local/mysql/include/ --with-mysql-libs=/usr/local/mysql/lib/"
---> Fetching sphinx
---> Verifying checksum(s) for sphinx
---> Extracting sphinx
---> Configuring sphinx
---> Building sphinx with target all
---> Staging sphinx into destroot
---> Installing sphinx 0.9.7_0
---> Activating sphinx 0.9.7_0
---> Cleaning sphinx

Voila. Let’s start ThinkingSphinx:

$ rake thinking_sphinx:start
Sphinx 0.9.7
Copyright (c) 2001-2007, Andrew Aksyonoff

ERROR: malformed or unknown option near '--pidfile'.

usage: searchd [--config file.conf] [--console]
rake aborted!

WTF? Again, Google to the rescue. It seems that the --pidfile option which is used by ThinkingSphinx was added only in version 0.9.8 of Sphinx… but MacPorts doesn’t have that version. Or does it? The MacPorts project page for Sphinx shows that it should be at 0.9.8. So why am I getting 0.9.7?

After a next session of googling I figured out that I may need to upgrade the ports system itself – apparently the newest version of the Sphinx port was somehow incompatible with the older version of ports. MacPorts can be updated with the command port selfupdate:

$ sudo port selfupdate

MacPorts base version 1.600 installed

Downloaded MacPorts base version 1.710
Configuring, Building and Installing new MacPorts base
selfupdate done!

Indeed, this time port search showed Sphinx 0.9.8:

$ sudo port uninstall sphinx
---> Deactivating sphinx @0.9.7_0
---> Uninstalling sphinx @0.9.7_0
$ port search sphinx
sphinx @0.9.8 (textproc, net)
Sphinx is a full-text search engine

One last trap: this time, Sphinx port has explicitly set MySQL as a dependency – and since it thinks I don’t have it yet, it starts to download and compile the MySQL port… which of course I don’t want – why the hell would I need two separate MySQLs?

To convince MacPorts I didn’t need it, I needed another option: depends_lib. Here’s the command that finally worked:

$ sudo port install sphinx configure.args="--with-mysql-includes=/usr/local/mysql/include/ --with-mysql-libs=/usr/local/mysql/lib/" depends_lib=""
---> Fetching sphinx
---> Attempting to fetch sphinx-0.9.8.tar.gz from
---> Verifying checksum(s) for sphinx
---> Extracting sphinx
---> Configuring sphinx
---> Building sphinx
---> Staging sphinx into destroot
---> Installing sphinx @0.9.8_0
---> Activating sphinx @0.9.8_0
---> Cleaning sphinx

By the way – a few days later I found a new package management system for MacOSX, called Homebrew – it’s written in Ruby, and it looks rather new so it may be a bit unstable yet, but the readme claims that it’s much better designed that MacPorts:

We optimise for Leopard Intel, binaries are stripped, compile flags tweaked. Nobody wants crappy, slow software. Apart from MacPorts and Fink.

I think I’ll give it a try next time…

Update (19.12.2009): I’ve uninstalled MacPorts completely on all my computers, and now I install everything through Homebrew. It works much faster and doesn’t download half of the repository to install one package… As for Sphinx, you still need to disable MySQL dependency and add an option to configure, but it’s easier to figure out how to do this than with MacPorts (just open the sphinx.rb formula and you’ll know what to do).



I'll tell you a story how this looks like on Gentoo:

emerge app-misc/sphinx

the end :D


... I hate you :P


Thanks for tutorial :)


You, sir, are a gentleman.

Thanks Jakub, it's been really helpful

Leave a comment


This will only be used to display your Gravatar image.


What class method do you use in Ruby to define a read-only property?