You are using an outdated browser which puts all net citizens at risk. As an incentive to upgrade to a current and thus much more secure product (we recommend the free Firefox browser), you won't be able to visit this site in its cute design, but in this rather boring printer-ready version only. Thank you for considering a browser update!

Gentoo Prefix on Mac OS X

Open Source on Mac OS X

There are a few ways how to spice up your Mac with unixish Open Source software: Fink uses the Debian package manager and overall works pretty well, yet it seems as if it has been loosing momentum lately, many package versions date back quite a bit. A reason for this could be MacPorts (formerly know as Darwin Ports) which generally features more up-to-date package versions. Unfortunately, it's package manager falls short in many areas, most notably very poor dependency handling.

Thus I'm rather unhappy with either of them, especially as our servers are running Gentoo Linux and I've soon come to love the power of it's package manager Portage. Why can't there be anything like that on Mac OS X?

Gentoo Prefix

Well, there is! The project is called Gentoo Prefix and aims at bootstrapping Gentoo Linux in any subdirectory you choose. Gentoo is a source distribution which has to be compiled on your Mac, thus the initial installation takes more time than with precompiled distributions. Yet it's painless and you're rewarded with all the power of Gentoo and Portage running right on your Mac OS X Mach kernel.

Installation

The installation is possible on all kind of platforms. There is an excellent guide available for Gentoo Prefix on Mac OS X.

Once finished with the guide, it's a good idea to extend both the profiles of Gentoo Prefix and Mac OS X in order to have access to all commands either way. However, Portage must not be used but from within a Gentoo Prefix session.

Add the following to /etc/profile:

export PATH="$PATH:/Gentoo/usr/bin:/Gentoo/bin:/Gentoo/opt/bin:/Gentoo/usr/sbin:/Gentoo/sbin"
export MANPATH="$MANPATH:/Gentoo/usr/share/man"

Then add the following to {PREFIX}/etc/profile:

export PATH="$PATH:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin"
export MANPATH="$MANPATH:/usr/local/man:/usr/share/man:/usr/local/share/man:/usr/X11/man"

Unfortunately, the above PATHs are not effective for scripts using shebang lines such as #!/bin/bash. To fix this, open a new Gentoo Prefix terminal, dump the PATHs and set them in environment.plist accordingly. When done, you have to logout and re-login in order to bring these changes into effect:

set | grep PATH
open ~/.MacOSX/environment.plist

A few very handy ebuilds are not installed in the bootstrapping, so emerge them now:

emerge --ask gentoolkit joe

And maybe you wish to add a few handy aliases globally to {PREFIX}/etc/bash/bashrc such as:

alias emerge-test='emerge --update --deep --newuse --pretend world'
alias emerge-update='emerge --ask --update --deep --newuse world'
alias less='less -r'
alias more='less -r'
alias diff='diff -urNa'
alias pico='jpico'
alias edit='jpico'
alias exit='clear; exit'

Add the following lines to /Gentoo/etc/make.conf in order to have the warnings occurring during an emerge sent as an email to yourself and saved to the log directory:

PORTAGE_ELOG_CLASSES="warn error log"
PORTAGE_ELOG_SYSTEM="mail:warn,error,log save"
PORTAGE_ELOG_MAILURI="{YOUR_EMAIL} /usr/sbin/sendmail"
PORTAGE_ELOG_MAILFROM="localhost"
PORTAGE_ELOG_MAILSUBJECT="\${PACKAGE} emerged on \${HOST}"

Portage Cheat Sheet

Here are the most common Portage bits you're going to need in order to keep your Mac up-to-date:

Command                                    Description
emerge --syncUpdate the local mirror of the portage package repository. Execute this before you use any of the following commands.
emerge --search {KEYWORD}Search for software. Or use the more concise online package search.
emerge --ask -v {PACKAGE}Install a software package. Dependencies are treated. The -v increases the verbosity to include USE flags.
emerge --buildpkgonly {PACKAGE}
emerge --usepkgonly {PACKAGE}
Same as the above in two steps: The first steps compiles the package (all dependencies must be installed already) and the second one installs the files. This procedure is suitable if short service downtime is important.
emerge --ask ={PACKAGE}-{VERSION}Install a specific version of a software package, great for downgrading. Dependencies are treated.
emerge --ask --update --deep --newuse worldUpdate all installed software.
emerge @preserved-rebuildIf an emerge fails, the reason is often a broken dependency. This first command shows a list of packages which appear to be broken and should be rebuilt with the second command.
emerge --ask --resumeResume the last install where it unexpectedly terminated, for instance due to a network outage between the server and the terminal.
emerge --ask --resume --skipfirstSame as above, but skip the first pending package. This comes in handy if a package in the update list is failing to compile as this command skips it and continues with the subsequent packages.
emerge --unmerge {PACKAGE}Uninstall a software package. Dependencies are NOT treated.
equery belongs {FILE}Find out to what software package a particular file belongs to.
equery listList all installed packages.
/Gentoo/sbin/depscan.sh --updateFixes error "Re-caching dependency info (mtimes differ)" which sometimes occurs after installing ebuilds.
emerge --digest {PACKAGE}Fixes error "Digest verification Failed: - /usr/portage/distfiles/distributionfile.tgz - Reason: Filesize does not match recorded size". Use it only if you are sure that the local package has not been altered by evildoers.
eclean distfilesRemove outdated distribution files that are no longer needed.

(Sven Schwyn)

Comments

goockoupt said on Friday, April 10, 2009:

hm.. cognitively.

shossetep said on Thursday, April 16, 2009:

hmm… thank you

kdb424 said on Wednesday, September 08, 2010:

As a Gentoo user, this was a really helpful guide to get more of portage working in my mac environment. Thanks you very much for the amazing guide.

jasonb said on Saturday, January 05, 2013:

The link to the page showing how to install the Gentoo Prefix for Mac OS X is now dead. The replacement link appears to be: http://www.gentoo.org/proj/en/gentoo-alt/prefix/bootstrap-solaris.xml

Thanks!

(We are remaking our web presence and therefore comments are temporary disabled.)