Wondering why is this necessary? Citing MacPorts,
An installation of MacPorts and the ports installed by it are only designed to work on a single OS release and a single CPU architecture. If you upgrade to a new OS version (e.g. from Tiger to Leopard) or migrate to a new machine with a different type of CPU (e.g. PowerPC to Intel), you may get lucky and have your ports keep working, but in general, things will break.
Fairly recently, my Mac underwent an upgrade from Leopard to Snow Leopard and not knowing that I needed to upgrade MacPorts to keep things sane, I tried installing Qt Octave – an open source equivalent of MATLAB [more about this in a subsequent post]. Needless to say, things started breaking and result was a [lot] more time consuming process of upgrading MacPorts.
Part #0. Upgrading/Re-installing XCode
First step is to download XCode 3 for Snow Leopard from Apple Developer Connection [one needs to create an account to download the DMG but it’s free]. One needs to ensure that the optional components for command line development are installed as well (Unix Development in the XCode 3.x installer). Unfortunately, XCode is not upgraded automagically during the regular/routine software updates but the installation went smooth and just for good measure, I rebooted the machine.
Part #1. Upgrading MacPorts
Download the appropriate .pkg file from MacPorts and complete the installation of base package. This went [should go] smooth as well. Once the installation is complete, run the following command in a terminal:
sudo port -v selfupdate
If this results in an error port: command not found, update the definition of PATH variable [in $HOME/.bashrc] to include /opt/local/bin:
export PATH="${PATH}:/opt/local/bin"
Save the $HOME/.bashrc and source it via
. $HOME/.bashrc
Part #2. Re-installing Ports
Part of this stage is really easy – make a list of installed ports and remove all the installed ports. To accomplish these:
sudo port installed > $HOME/installed_ports.txt
sudo port clean installed
sudo port -f uninstall installed
The most time consuming [and as such most boring/entertaining] part is re-installing all the required/active ports – one at a time – by going through $HOME/installed_ports.txt. To significantly simplify this process and reduce the associated boredom/entertainment, I did the following:
grep "active" $HOME/installed_ports.txt | awk -F ' ' '{print $1}' > $HOME/active_ports.txt
I read through $HOME/active_ports.txt and removed duplicate entries if any as well as retained only the highest / most recent version of any given port. I then used the following shell script, port_reinstall.sh, to install them:
#! /bin/bash
# BASH script to re-install previously installed ports on an Apple Mac
# The list of active ports is imported from $HOME/active_ports.txt
# and this list varies from person to person, depending on what (s)he
# has installed previously.
#
# Gowtham, Tue Oct 20 22:23:36 EDT 2009
export ACTIVE_PORTS="apr
apr-util
aquaterm
arpack
atk
autoconf
automake
bluefish
bzip2
cairo
cmake
coreutils
curl
cyrus-sasl2
db46
docbook-xml
docbook-xsl
expat
fftw-3
fftw-3-single
fontconfig
freetype
gawk
gcc43
gd2
gettext
ghostscript
git-core
glib2
gmake
gmp
gnome-common
gnome-icon-theme
gnuplot
gperf
gqview
GraphicsMagick
groff
gsed
gtk-doc
gtk2
help2man
hicolor-icon-theme
icon-naming-utils
ImageMagick
intltool
jmol
jpeg
libart_lgpl
libglade2
libiconv
libidn
libpixman
libpng
libtool
libxml2
libxslt
lzmautils
m4
metis
mpfr
ncurses
ncursesw
neon
openssl
p5-compress-raw-zlib
p5-compress-zlib
p5-crypt-ssleay
p5-error
p5-html-parser
p5-html-tagset
p5-io-compress-base
p5-io-compress-zlib
p5-libwww-perl
p5-locale-gettext
p5-svn-simple
p5-term-readkey
p5-uri
p5-xml-namespacesupport
p5-xml-parser
p5-xml-sax
p5-xml-simple
pango
pcre
pdflib
perl5.8
pkgconfig
plotutils
popt
readline
render
rsync
scrollkeeper
serf
shared-mime-info
sqlite3
subversion
subversion-perlbindings
SuiteSparse
teTeX
texi2html
texinfo
tiff
urw-fonts
wget
Xft2
xmlcatmgr
xorg-bigreqsproto
xorg-inputproto
xorg-kbproto
xorg-libice
xorg-libsm
xorg-libX11
xorg-libXau
xorg-libXaw
xorg-libXdmcp
xorg-libXext
xorg-libXmu
xorg-libXt
xorg-renderproto
xorg-util-macros
xorg-xcmiscproto
xorg-xextproto
xorg-xf86bigfontproto
xorg-xproto
xorg-xtrans
xpm
xrender
zlib"
for x in $ACTIVE_PORTS
do
sudo port install $x
sleep 5
done
Once this file is saved, run this as
./port_reinstall.sh 2>&1 | tee $HOME/port_reinstall_00.txt
and keep entering password when the process demands. Once the process is completed [could take hours, depending how many ports need to be installed, their dependencies and the network speed], make sure to read through $HOME/port_reinstall_00.txt – to learn about errors messages/warnings/notification of further actions, if any. After taking care of those things, run the script again – for good measure:
./port_reinstall.sh 2>&1 | tee $HOME/port_reinstall_01.txt
This process should preferably complete within minutes and the machine should be ready to use as before.
Request
If you find errors in this approach and/or know of better [more elegant] methods to accomplish the same, please do let me [and other readers] know of it by posing them as comments. They will be greatly appreciated.