Running mlocate on Mac OS X

Posted by chetan on June 25, 2010 in computers suck

After suffering through yet another morning of ‘find’ pegging my CPU and grinding my sad little laptop hard drive for a couple of hours, I finally decided to rectify the situation. Most Linux distributions these days ship mlocate by default, and so I decided to give it a go on OS X. Unfortunately, it doesn’t quite support OS X out of the box yet. I’ll spare you all the miserable details (it was an epic struggle getting this compiled), but I finally managed to get it working.

Here’s how:

# first we get the source and patch it
$ hg clone
$ cd mlocate
$ wget '' -O mlocate-mountlist-hg.2.diff
$ hg import mlocate-mountlist-hg.2.diff
# prep
$ cd ..
$ git clone git://
$ cd mlocate
$ ../gnulib/gnulib-tool --import
$ mv gnulib/lib/stat-time.h~ gnulib/lib/stat-time.h
$ cp ../gnulib/lib/canonicalize.h gnulib/lib/
$ autoreconf --install --force
# install
$ ./configure
$ make
$ sudo make install

Ok, now we have the binaries in place; we’re almost there! One last thing to do, and that’s create a new user account and group for mlocate. After running updatedb it will try to chown the locate db as the user ‘mlocate’, so we need to make sure this users exists. Unfortunately, there’s no adduser command in OS X and it’s a little bit of a pain, so I wrote this little script to take care of it for you. Grab it here.

Simply run it like so:

$ adduser 
username: mlocate
home dir [default=/var/empty]: 
group id (default=700):
user id (default=700):
real name (default=daemon): 
shell: (default=/usr/bin/false):

All done! Now let’s try updating the db –

$ sudo /usr/local/bin/updatedb

And that should be it. I still ran into a couple of problems with permissions so your best bet is to fix them every time you run updatedb (just stick it in cron):

$ chmod 664 /usr/local/var/mlocate/mlocate.db

Now wasn’t that easy?

PS. If you don’t have Mercurial (hg) or Git installed, get them here:

Updated (July 23, 2010): You may need newer versions of automake and autoconf as well. I had problems with 1.5 and 2.63 respectively but upgrading to 1.11 and 2.65 (with fink) worked fine.


Leave a response

  1. David Tue, 08 Nov 2011 11:06:42 EST

    you should create a homebrew recipe for this! Awesome!